{***********************************************************************}
{									}
{ __ZapWin    Remove a window record from the record list		}
{									}
{ function  __ZapWin(var WinPtr : _WindowPtr): boolean; 		}
{									}
{	      WinPtr	Pointer to _Window record to be removed from	}
{			the record list.				}
{									}
{ Description This procedure removes the specified record from the	}
{	      record list.  If WinPtr is an active window, it is made	}
{	      current using __TopWin and then removed using __RemWin.	}
{	      If WinPtr^ is not in the list, then __ZapWin returns	}
{	      FALSE.  The record structure is deleted by adjusting the	}
{	      pointers of the records "underneath" and "on top" the	}
{	      window. Finally, if the window is successfully deleted,	}
{	      the pointer to the removed window is set to NIL and the	}
{	      space allocated for the window record is released.	}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

function  __ZapWin(var WinPtr : _WindowPtr): boolean;

  var
    TempPtr   : _WindowPtr;
    ImagePtr  : Pointer;
    Found     : boolean;

  begin {__ZapWin}

    { Check that WinPtr^ really exists. 				}

    __ZapWin := FALSE;		       { if no premature exit, the func-}
    Found    := FALSE;		       { tion value is set to TRUE.	}
    TempPtr  := _WinRoot;
    while ((not Found) and (TempPtr <> NIL)) do
      if (TempPtr = WinPtr) then
	 Found := TRUE
      else
	 TempPtr := TempPtr^._WinTop;
    if (not Found) then
       Exit;			       { No record found, so return.	}

    if (WinPtr^._Active) then	       { If the window is active, make	}
       begin			       { sure it is current, and then	}
	 Found := __TopWin(WinPtr);    { remove it.			}
	 Found := __RemWin
       end;

    with WinPtr^ do		       { Now adjust all pointers for	}
      begin			       { the deletion of the record.	}
	if (WinPtr = _WinRoot) then
	   _WinRoot := _WinTop
	else
	  _WinUnder^._WinTop := _WinTop;
	if (WinPtr = WinLast_) then
	   WinLast_ := _WinUnder
	else
	   _WinTop^._WinUnder := _WinUnder
      end;
    Dispose(WinPtr);
    WinPtr   := NIL;
    __ZapWin := TRUE

  end;	{__ZapWin}
