{***********************************************************************}
{									}
{ __DelItMnu  Delete a menu item					}
{									}
{ function  __DelItMnu(MenuPtr : _MenuPtr; Col,Row : byte) : boolean;	}
{									}
{	      MenuPtr	Pointer to the menu descriptor returned by	}
{			__MakeMnu when the menu was constructed.	}
{	      Col,Row	Item's position within the window		}
{									}
{ Description This function deletes one _Item in the linked list of	}
{	      _Items associated with a menu.				}
{									}
{	      This function first finds the specified item, removes	}
{	      any _Key records which point to the item, removes the	}
{	      item from the linked list, and finally frees the memory	}
{	      used by the item and its associated structures.		}
{									}
{	      Note that items deleted from  a  currently  visible	}
{	      menu will not be removed from the display until the	}
{	      menu is displayed again using __DispMnu.			}
{									}
{	      __DelItMnu returns TRUE  if the  item was found and	}
{	      successfully deleted, FALSE on failure.			}
{									}
{	      On error _MenuError may be set to:  _InvalidMenu		}
{						  _InvalidItem		}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc. 1987		}
{_______________________________________________________________________}

function __DelItMnu(MenuPtr : _MenuPtr; Col,Row : byte) : boolean;

  var
    TempPtr	  : _ItemPtr;
    KPtr, LastPtr : _KeyPtr;
    Found	  : boolean;
    ColRow	  : word;

  begin {__DelItMnu}

    __DelItMnu := FALSE;

    { Invoke __RetItMnu to validate the request and returnt a pointer	}
    { to the item.							}

    TempPtr := __RetItMnu(MenuPtr,Col,Row);
    if (TempPtr = NIL) then
       Exit;

    { Reset the pointers to remove the item from the list.		}

    if (TempPtr = MenuPtr^._MItemsPtr) then
       MenuPtr^._MItemsPtr := TempPtr^._NextItem
    else
       TempPtr^._PrevItem^._NextItem := TempPtr^._NextItem;

    if (MenuPtr^._MITailPtr = TempPtr) then
       MenuPtr^._MITailPtr := TempPtr^._PrevItem;

    if (TempPtr^._NextItem <> NIL) then
       TempPtr^._NextItem^._PrevItem := TempPtr^._PrevItem;

    { Free any keys that point to this item.				}

    KPtr      := MenuPtr^._MKeysPtr;
    LastPtr   := KPtr;
    While (KPtr <> NIL) do
      begin
	if (KPtr^._KeyItem = TempPtr) then
	   begin

	     { Reset pointers to exclude deleted item and release the	}
	     { memory used by the key structures.			}

	     if (KPtr = MenuPtr^._MKeysPtr) then
		MenuPtr^._MKeysPtr := KPtr^._NextKey
	     else
		LastPtr^._NextKey  := KPtr^._NextKey;
	     KPtr^._KSig := ' ';		 { Erase signature	}
	     FreeMem(KPtr,sizeof(_Key)) 	 { Release the memory	}
	   end;
	LastPtr := KPtr;
	KPtr	:= KPtr^._NextKey
      end;

    { Free memory used by the item structure.			   }

    with TempPtr^ do
      begin
	_ISig := ' ';
	FreeMem(_ItemStrPtr,_Len + 1);
	if (_LDescPtr <> NIL) then
	   FreeMem(_LDescPtr,_LDescLen + 1);
      end;
    FreeMem(TempPtr,sizeof(_Item));
    __DelItMnu := TRUE

  end;	{__DelItMnu}
