(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
unit AHMTMenusDsgn;
{$I AHM.INC}
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls,AHMMenu,DsgnIntf,DsgnWnds,LibIntf, Buttons, ExtCtrls,
  Menus,CommCtrl,AHMMenuClass,AHMMenuConst,AHMTMenuDsgnWnd;

type
  TAHMMenuBuilder = class(TAHMMenuDsgnWnd)
  private
    Panel : TPanel;
    AHMMenuTree : TTreeview;
    TestButton,DeleteButton,AddButton,InsertButton : TBitbtn;
    procedure DoKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
    procedure AddButtonClick(Sender: TObject);
    procedure DeleteButtonClick(Sender: TObject);
    procedure InsertButtonClick(Sender: TObject);
    procedure TestButtonClick(Sender: TObject);
    procedure DoAbout(Sender: TObject);
    procedure DoFormClose(Sender: TObject; var Action: TCloseAction);
    procedure SetNodeImage(Node : TTreeNode);
    procedure AHMMenuTreeGetSelectedIndex(Sender: TObject; Node: TTreeNode);
    procedure AHMMenuTreeEdited(Sender: TObject; Node: TTreeNode; var S: String);
    procedure AHMMenuTreeDblClick(Sender: TObject);
    procedure AHMMenuTreeMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure AHMMenuTreeDragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure AHMMenuTreeDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
    procedure FormActivate(Sender: TObject);
    procedure BuildMenuStructure(MTopItem : TAHMMenuItem;const TopTreeNode : TTreeNode);
  protected
    procedure Activated; override;
    procedure SetupMenuBuilder;
  public
    AHMBuilderMenu : TPopupMenu;
    procedure FormModified; override;
    {$IFDEF AHMINPRISE4}
    procedure ComponentDeleted(Component: IPersistent); override;
    {$ELSE}
    procedure ComponentDeleted(Component:TComponent); override;
    {$ENDIF}
    {$IFDEF AHMINPRISE3}
    procedure FormClosed(AForm:TCustomForm); override;
    {$ELSE}
    procedure FormClosed(AForm:TForm); override;
    {$ENDIF}
    destructor Destroy; override;
  end;
  TAHMMenuProperty = class(TPropertyEditor)
  public
    procedure Edit; override;
    function GetValue: string; override;
    function GetAttributes: TPropertyAttributes; override;
  end;
  TAHMAboutMenus = class(TStringProperty)
  public
    procedure Edit; override;
    function GetValue: string; override;
    function GetAttributes: TPropertyAttributes; override;
  end;
  TAHMMenuComponentEditor = class(TComponentEditor)
  public
    procedure ExecuteVerb(Index:integer); override;
    function GetVerb(Index:integer):string; override;
    function GetVerbCount:integer; override;
  end;
  TAHMBarFontNameProperty = class(TStringProperty)
  public
    procedure GetValues(Proc: TGetStrProc); override;
    function GetAttributes: TPropertyAttributes; override;
  end;

var AHMMenuBuilder: TAHMMenuBuilder=nil;
    INTopMenuItem : TAHMMenuItem;
    MenuOwner : TComponent;

procedure Register;

implementation
{$R AHMMENU.res}

uses TypInfo;

procedure Register;
begin
  RegisterClasses([TAHMMenuItem]);
  RegisterNoIcon([TAHMMenuItem]);
  RegisterComponents('AHM Menus',[TAHMMainMenu,TAHMPopupMenu,TAHMFormMenu,TAHMApplicationMenu]);
  RegisterPropertyEditor(TypeInfo(TAHMMenuItem),TAHMMenu,'Items',TAHMMenuProperty);
  RegisterPropertyEditor(TypeInfo(String),TAHMMenu,'AboutMenus',TAHMAboutMenus);
  RegisterPropertyEditor(TypeInfo(String),TAHMSubMenu,'BarFontName',TAHMBarFontNameProperty);
  RegisterComponentEditor(TAHMMenu,TAHMMenuComponentEditor);
end;


procedure BuildMenu(Const TopMenuItem : TAHMMenuItem;OnOwner : TComponent;FormDsgn :{$IFDEF AHMINPRISE4}IFormDesigner{$ELSE}TFormDesigner{$ENDIF});
var TopTreeItem : TTreeNode;
begin
  if OnOwner<>MenuOwner then AHMMenuBuilder.Free;
  if AHMMenuBuilder<>nil then AHMMenuBuilder.BringToFront else
  begin
    {$WARNINGS OFF}AHMMenuBuilder:=TAHMMenuBuilder.Create(Application);{$WARNINGS ON}
    AHMMenuBuilder.SetupMenuBuilder;
    with AHMMenuBuilder do
    begin
      MenuOwner := OnOwner;
      InTopMenuItem:=TopMenuItem;
      TopTreeItem:=AHMMenuTree.Items.Add(nil,MenuOwner.Name);
      BuildMenuStructure(TopMenuItem,TopTreeItem);
      AHMMenuTree.Font:=TAHMMenu(OnOwner).MenuFont;
      AHMMenuTree.Items.GetFirstNode.Expand(False);
      AHMMenuTree.Items.GetFirstNode.ImageIndex:=-1;
      AHMMenuTree.Items.GetFirstNode.SelectedIndex:=-1;
    end;
  end;
  begin
    with AHMMenuBuilder do
    begin
      AHMMenuBuilder.Designer:=FormDsgn;
      Showhint:=False;
      ParentShowHint:=False;
      AHMMenuTree.ShowHint:=False;
      AHMMenuTree.ParentShowHint:=False;
      show;
    end;
  end;
end;

procedure TAHMBarFontNameProperty.GetValues(Proc: TGetStrProc);
var I: Integer;
begin
  for I := 0 to Screen.Fonts.Count - 1 do Proc(Screen.Fonts[I]);
end;

function TAHMBarFontNameProperty.GetAttributes: TPropertyAttributes;
begin
  result:=[paMultiSelect, paValueList, paSortList, paRevertable];
end;


procedure TAHMAboutMenus.Edit;
begin
  ShowMenusAbout;
end;

function TAHMAboutMenus.GetValue: string;
begin
  FmtStr(Result, '(%s)', ['About AHM Menus']);
end;

function TAHMAboutMenus.GetAttributes: TPropertyAttributes;
begin
  Result := [paMultiSelect,paDialog,paReadOnly];
end;


procedure TAHMMenuProperty.Edit;
begin
  BuildMenu(TAHMMenuItem(GetOrdValue),(TAHMMenuItem(GetOrdValue).Owner),Self.Designer);
end;

function TAHMMenuProperty.GetValue: string;
begin
  FmtStr(Result, '(%s)', ['Menu Builder']);
end;

function TAHMMenuProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog,paReadOnly];
end;

procedure TAHMMenuBuilder.BuildMenuStructure(MTopItem : TAHMMenuItem;const TopTreeNode : TTreeNode);
var CurrentItemsCount: Integer;
begin
  for CurrentItemsCount:=0 to MTopItem.count-1 do
  BuildMenuStructure(MTopItem.Items[CurrentItemsCount],AHMMenuTree.Items.AddChildObject
       (TopTreeNode,MTopItem.Items[CurrentItemsCount].Caption,MTopItem.Items[CurrentItemsCount]));
  SetNodeImage(TopTreeNode);
end;

procedure TAHMMenuBuilder.Activated;
begin
  if (AHMMenuTree.Selected=nil) then
  if (InTopMenuItem.Count>0) then
  begin
    Designer.SelectComponent(InTopMenuItem.Items[0]);
    AHMMenuTree.Selected:=AHMMenuTree.TopItem.GetFirstChild;
  end else
  begin
    Designer.SelectComponent(MenuOwner);
    AHMMenuTree.Selected:=AHMMenuTree.Items.GetFirstNode;
  end;
end;

procedure TAHMMenuBuilder.SetNodeImage(Node : TTreeNode);
begin
  if Node.Data<>nil then
  if assigned(TAHMMenu(MenuOwner).Images) then
  begin
    AHMMenuTree.Images:=TAHMMenu(MenuOwner).Images;
    if not(TAHMMenuItem(Node.Data).Enabled) and (TAHMMenuItem(Node.Data).DisabledImageIndex<>-1) then
      Node.Imageindex:=TAHMMenuItem(Node.Data).DisabledImageIndex
    else
    if (TAHMMenuItem(Node.Data).Checked) and (TAHMMenuItem(Node.Data).CheckedIndex<>-1)  then
      Node.Imageindex:=TAHMMenuItem(Node.Data).CheckedIndex
    else
      Node.Imageindex:=TAHMMenuItem(Node.Data).ImageIndex;
    Node.SelectedIndex:=Node.ImageIndex;
  end;
end;

procedure TAHMMenuBuilder.FormModified;
Procedure ApplyChanges(CurrentNode : TTreeNode);
var I : Integer;
begin
  if (CurrentNode<>nil) and (CurrentNode<>AHMMenuTree.Items.GetFirstNode) then
  begin
    CurrentNode.Text:=TAHMMenuItem(CurrentNode.Data).Caption;
    SetNodeImage(CurrentNode);
  end;
  for I:=0 to CurrentNode.Count-1 do ApplyChanges(CurrentNode.Item[i]);
end;
begin
 ApplyChanges(AHMMenuTree.Items.GetFirstNode);
 AHMMenuTree.Font:=TAHMMenu(MenuOwner).MenuFont;
end;

procedure TAHMMenuBuilder.AddButtonClick(Sender: TObject);
var SelMenuItem : TAHMMenuItem;
    NewComp : TComponent;
begin
  if AHMMenuTree.Selected<>nil then
  begin
    SelMenuItem:=TAHMMenuItem(AHMMenuTree.Selected.Data);
    if SelMenuItem=nil then SelMenuItem:=InTopMenuItem;
    NewComp:=self.Designer.CreateComponent(TAHMMenuItem,SelMenuItem,0,0,0,0);
    SelMenuItem.Add(NewComp as TAHMMenuItem);
    (NewComp.owner as TWinControl).Refresh;
    (NewComp as TAHMMenuItem).Caption:=(NewComp as TAHMMenuItem).Name;
    Self.Designer.Modified;
    AHMMenuTree.Selected:=AHMMenuTree.Items.AddChildObject(AHMMenuTree.Selected,(NewComp as TAHMMenuItem).Caption,(NewComp as TAHMMenuItem));
    AHMMenuTree.Selected.ImageIndex:=-1;
    AHMMenuTree.Selected.SelectedIndex:=AHMMenuTree.Selected.ImageIndex;
    AHMMenuTree.Selected.EditText;
 end;
end;


procedure TAHMMenuBuilder.DoFormClose(Sender: TObject;var Action: TCloseAction);
begin
  Self.PopupMenu:=nil;
  MenuOwner:=nil;
  Action:=caFree;
end;

destructor TAHMMenuBuilder.Destroy;
begin
  inherited Destroy;
  AHMMenuBuilder:=nil;
end;

procedure TAHMMenuBuilder.DeleteButtonClick(Sender: TObject);
var DeletedMenuItem,ParentMenuItem : TTreeNode;
Function NotMoveable(AMenuItem : TTreeNode) : Boolean;
begin
  result:=(AMenuItem=nil) or (AMenuItem=AHMMenuTree.Items.GetFirstNode);
end;
begin
  AHMMenuTree.SetFocus;
  if NotMoveable(AHMMenuTree.Selected) then Exit else DeletedMenuItem:=AHMMenuTree.Selected;
  if DeletedMenuItem.Data<>nil then
  begin
    TAHMMenuItem(DeletedMenuItem.Data).Free;
    DeletedMenuItem.Data:=nil;
  end;
  ParentMenuItem:=DeletedMenuItem.Parent;
  if NotMoveable(ParentMenuItem) then
  begin
    AHMMenuTree.Selected:=AHMMenuTree.Items.GetFirstNode;
    Designer.SelectComponent(MenuOwner);
  end else
  begin
    AHMMenuTree.Selected:=ParentMenuItem;
    Designer.SelectComponent(TComponent(ParentMenuItem.Data));
  end;
  AHMMenuTree.Items.Delete(DeletedMenuItem);
  Designer.Modified;
end;

{$IFDEF AHMINPRISE4}
procedure TAHMMenuBuilder.ComponentDeleted(Component: IPersistent);
{$ELSE}
procedure TAHMMenuBuilder.ComponentDeleted(Component:TComponent);
{$ENDIF}
begin
  {$IFDEF AHMINPRISE4}
  if ExtractPersistent(Component)=(MenuOwner as TPersistent) then
  {$ELSE}
  if Component=MenuOwner then
  {$ENDIF}
  begin
//    SelfSelect(nil);
    MenuOwner:=nil;
    Release;
  end;
  inherited;
end;


{$IFDEF AHMINPRISE3}
procedure TAHMMenuBuilder.FormClosed(AForm:TCustomForm);
{$ELSE}
procedure TAHMMenuBuilder.FormClosed(AForm:TForm);
{$ENDIF}
begin
  MenuOwner:=nil;
  Release;
  inherited;
end;

procedure TAHMMenuBuilder.InsertButtonClick(Sender: TObject);
var SelMenuItem : TAHMMenuItem;
    NewComp : TComponent;
    InsertComp : Boolean;
begin
  if (AHMMenuTree.Selected<>nil) then
  begin
    InsertComp:=not(AHMMenutree.Selected=AHMMenuTree.Items.GetFirstNode);
    SelMenuItem:=TAHMMenuItem(AHMMenuTree.Selected.Data);
    if SelMenuItem=nil then SelMenuItem:=InTopMenuItem;
    NewComp:=Self.Designer.CreateComponent(TAHMMenuItem,SelMenuItem,0,0,0,0);
    if InsertComp then SelMenuItem.Parent.Insert(AHMMenuTree.Selected.Index,(NewComp as TAHMMenuItem))
    else SelMenuItem.Add(NewComp as TAHMMenuItem);
    (NewComp as TAHMMenuItem).Caption:=(NewComp as TAHMMenuItem).Name;
    Self.Designer.Modified;
    if InsertComp then
      AHMMenuTree.Selected:=AHMMenuTree.Items.InsertObject(AHMMenuTree.Selected,(NewComp as TAHMMenuItem).Caption,(NewComp as TAHMMenuItem))
    else
      AHMMenuTree.Selected:=AHMMenuTree.Items.AddChildObject(AHMMenuTree.Selected,(NewComp as TAHMMenuItem).Caption,(NewComp as TAHMMenuItem));
    AHMMenuTree.Selected.ImageIndex:=-1;
    AHMMenuTree.Selected.SelectedIndex:=AHMMenuTree.Selected.ImageIndex;
    AHMMenuTree.Selected.EditText;
  end;
end;

procedure TAHMMenuBuilder.AHMMenuTreeGetSelectedIndex(Sender: TObject;
  Node: TTreeNode);
{$IFDEF AHMINPRISE5}
var FSelectList: TDesignerSelectionList;
{$ELSE}
var FSelectList: TComponentList;
{$ENDIF}

begin
  if (AHMMenuTree.Selected<>nil) then
  begin
  {$IFDEF AHMINPRISE5}
  FSelectList:=TDesignerSelectionList.Create;
  {$ELSE}
  FSelectList:=TComponentList.Create;
  {$ENDIF}

    if TAHMMenuItem(AHMMenuTree.Selected.Data)<>nil then
      FSelectList.Add(TAHMMenuItem(AHMMenuTree.Selected.Data))
    else
      FSelectList.Add(MenuOwner);
    Self.Designer.SetSelections(FSelectList);
    FSelectList.Free;
  end;
end;

procedure TAHMMenuComponentEditor.ExecuteVerb(Index:integer);
begin
  case Index of
    0 : BuildMenu(TAHMMenuItem((Component as TAHMMenu).Items),Component,Self.Designer);
  end;
end;

function TAHMMenuComponentEditor.GetVerb(Index:integer):string;
begin
  Result:=ahmmnudsgmenubuilder;
end;

function TAHMMenuComponentEditor.GetVerbCount:integer;
begin
  Result:=1;
end;

procedure TAHMMenuBuilder.AHMMenuTreeEdited(Sender: TObject;Node: TTreeNode; var S: String);
begin
  try
    TAHMMenuItem(AHMMenuTree.Selected.Data).Caption:=S
  except
    S:=Node.Text;
    raise Exception.Create(ahmmnudsgnonewname)
  end;
  AHMMenuTreeGetSelectedIndex(self,Node);
  Self.Designer.Modified; 
end;

procedure TAHMMenuBuilder.AHMMenuTreeDblClick(Sender: TObject);
begin
  if (AHMMenuTree.Selected.Data<>nil) then
  TDefaultEditor(GetComponentEditor(TAHMMenuItem(AHMMenuTree.Selected.Data),AHMMenuBuilder.Designer)).Edit;
end;


procedure TAHMMenuBuilder.TestButtonClick(Sender: TObject);
var pnt : TPoint;
begin
  Pnt:=TestButton.ClientToScreen(Point(0,TestButton.Height));
  (MenuOwner as TAHMMenu).Popup(Pnt.x,Pnt.y);
end;

procedure TAHMMenuBuilder.AHMMenuTreeMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if (Button=mbLeft) and (AHMMenuTree.GetNodeAt(X,Y)<>nil) and
  (AHMMenuTree.GetNodeAt(X,Y)<>AHMMenuTree.Items.GetFirstNode) then  AHMMenuTree.BeginDrag(False);
end;

procedure TAHMMenuBuilder.AHMMenuTreeDragDrop(Sender, Source: TObject; X,
  Y: Integer);
var
 AnItem: TTreeNode;
  HT: THitTests;
begin
  if AHMMenuTree.Selected = nil then Exit;
  HT := AHMMenuTree.GetHitTestInfoAt(X, Y);
  AnItem := AHMMenuTree.GetNodeAt(X, Y);
  if AnItem.HasAsParent(AHMMenuTree.Selected) then exit;
  if (AnItem<>nil) and (AnItem<>AHMMenuTree.Selected) and (AnItem<>AHMMenuTree.Items.GetFirstNode) then
  begin
    AHMMenuTree.Items.BeginUpdate;
    TAHMMenuItem(AHMMenuTree.Selected.Data).Parent.Remove(TAHMMenuItem(AHMMenuTree.Selected.Data));
    if ((HT - [htToRight,htOnLabel])=HT) then
    begin
      TAHMMenuItem(AnItem.Data).Parent.Insert(TAHMMenuItem(AnItem.Data).MenuIndex,TAHMMenuItem(AHMMenuTree.Selected.Data));
      AHMMenuTree.Selected.MoveTo(AnItem,naInsert);
    end else
    begin
      TAHMMenuItem(AnItem.Data).Insert(TAHMMenuItem(AnItem.Data).Count,TAHMMenuItem(AHMMenuTree.Selected.Data));
      AHMMenuTree.Selected.MoveTo(AnItem,naAddChild);
    end;
    AHMMenuTree.Items.EndUpdate;
    Self.Designer.Modified;
  end;
end;
procedure TAHMMenuBuilder.AHMMenuTreeDragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  Accept:=True;
end;

procedure TAHMMenuBuilder.FormActivate(Sender: TObject);
begin
 if (Application.Findcomponent('MenuBuilder') as TForm)<>nil
 then (Application.Findcomponent('MenuBuilder') as TForm).close;
end;

procedure TAHMMenuBuilder.SetupMenuBuilder;
Var AHMBuilderItem : TMenuItem;
begin
  Height:= 240;
  Width:= 320;
  BorderStyle:= bsToolWindow;
  Position:=poScreenCenter;
  KeyPreview:=True;
  Panel:=TPanel.Create(self);
  OnActivate:=FormActivate;
  OnClose:=DoFormClose;
  with Panel do
  begin
    Width:=320;
    Height:=35;
    Align:= altop;
    BevelOuter:= bvNone;
    Parent:=self;
    AddButton:=TBitBtn.Create(self);
    with AddButton do
    begin
      Parent:=Panel;
      Caption:=ahmmnudsgadd;
      OnClick:=AddButtonClick;
      Left:=4;
      Top:=4;
      Height:=25;
      Width:=75;
    end;
    InsertButton:=TBitBtn.Create(self);
    with InsertButton do
    begin
      Parent:=Panel;
      Caption:=ahmmnudsginsert;
      OnClick:=InsertButtonClick;
      Left:=80;
      Top:=4;
      Height:=25;
      Width:=75;
    end;
    DeleteButton:=TBitBtn.Create(self);
    with DeleteButton do
    begin
      Parent:=Panel;
      Caption:=ahmmnudsgdelete;
      OnClick:=DeleteButtonClick;
      Left:=156;
      Top:=4;
      Height:=25;
      Width:=75;
    end;
    TestButton:=TBitBtn.Create(self);
    with TestButton do
    begin
      Parent:=Panel;
      Caption:=ahmmnudsgtest;
      OnClick:=TestbuttonClick;
      Left:=232;
      Top:=4;
      Height:=25;
      Width:=75;
    end;
  end;
  AHMMenuTree:=TTreeview.Create(Self);
  with AHMMenuTree do
  begin
    Parent:=Self;
    Align:=alclient;
    HideSelection:=False;
    ParentFont:=False;
    ParentColor:=False;
    {$IFDEF AHMINPRISE4}
    ToolTips:=False;
    {$ENDIF}
    OnGetSelectedIndex:=AHMMenuTreeGetSelectedIndex;
    OnEdited:=AHMMenuTreeEdited;
    OnDblClick:=AHMMenuTreeDblClick;
    OnMouseDown:=AHMMenuTreeMouseDown;
    OnDragDrop:=AHMMenuTreeDragDrop;
    OnDragOver:=AHMMenuTreeDragOver;
    OnKeyDown:=DoKeyDown;
  end;
  AHMBuilderMenu:=TPopupMenu.Create(AHMMenuBuilder);
  with AHMBuilderMenu do
  begin
    Parent:=AHMMenuBuilder;
{    with PopupDetails do
    begin
      BarColor:=clred;
      BarEnabled:=True;
      BarCaption:=ahmmnubld1;
      BarFontName:='Tahoma';
      BarFontColor:=clYellow;
      BarAsGradient.Active:=True;
      Enabled:=True;
    end;
    MenuFont.Name:='Tahoma';
    SelectedFont.Name:='Tahoma';
    SelectedColor:=clBtnFace;
    SelectType:=selSunken;
    SelectedFont.Style:=[fsBold];
    DividerFont.Name:='Small Fonts';
    DividerFont.Size:=7;
    DividerFont.Style:=[fsBold];}
    AHMBuilderItem:=TMenuItem.Create(nil);
    with AHMBuilderItem do
    begin
      AHMBuilderMenu.Items.Add(AHMBuilderItem);
      Caption:=ahmmnudsgitem2;
      OnClick:=AddButtonClick;
    end;
    AHMBuilderItem:=TMenuItem.Create(nil);
    with AHMBuilderItem do
    begin
      AHMBuilderMenu.Items.Add(AHMBuilderItem);
      Caption:=ahmmnudsgitem3;
      OnClick:=InsertButtonClick;
    end;
    AHMBuilderItem:=TMenuItem.Create(nil);
    with AHMBuilderItem do
    begin
      AHMBuilderMenu.Items.Add(AHMBuilderItem);
      Caption:=ahmmnudsgitem4;
      OnClick:=DeleteButtonClick;
    end;
    AHMBuilderItem:=TMenuItem.Create(nil);
    with AHMBuilderItem do
    begin
      AHMBuilderMenu.Items.Add(AHMBuilderItem);
//      Divider:=True;
      Caption:='-';//ahmmnudsgitem5;
    end;
    AHMBuilderItem:=TMenuItem.Create(nil);
    with AHMBuilderItem do
    begin
      AHMBuilderMenu.Items.Add(AHMBuilderItem);
      Caption:=ahmmnudsgitem7;
      OnClick:=DoAbout;
    end;
  end;
  AHMMenuTree.PopupMenu:=AHMBuilderMenu;
end;

procedure TAHMMenuBuilder.DoAbout(Sender: TObject);
begin
  ShowMenusAbout;
end;


procedure TAHMMenuBuilder.DoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=VK_Delete then DeleteButtonClick(Self);
  if key=VK_INSERT then InsertButtonClick(Self);
end;


end.
