Create PopUp menu inside other PopUp

Posted in Components

Use Insert method for adding SubPopupItem to a PopUp menu.

procedure TForm1.MyShow(Sender: TObject);
begin
  with Sender as TMenuItem do ShowMessage(Caption);
end;

procedure TForm1.First1Click(Sender: TObject);
var
  MyPopUpItems: array[0..2] of TMenuItem;
  i: Integer;
begin
  for i:=0 to 2 do
  begin
    MyPopUpItems[i]:=TMenuItem.Create(Self);
    MyPopUpItems[i].Caption:='New item '+IntToStr(i);
    PopupMenu1.Items[1].Insert(i, MyPopupItems[i]);
    MyPopUpItems[i].OnClick:=MyShow;
  end;
end;