Examples Delphi

How to create and add a menuitem at runtime ?
type
TForm1 = class(TForm)
...
private
procedure MenuClick(Sender: TObject);
...
NewMenu := TMenuItem.Create(nil); // Self not needed
with NewMenu do
begin
Caption := '&Test';
OnClick := MenuClick; //
end;
MainMenu1.Items.Add(NewMenu); // New Main menu
MainMenu1.Items[0].Add(NewMenu); // New menuitem
NewItem
NewLine
MewMenu
NewPopupMenu
NewSubMenu
MainMenu1.Items.Add(NewItem('&Test', 0, True, True, nil, 1101, ''));
MainMenu1.Items[0].Add(NewSubMenu('&Test', 0, 'AName2',
[NewItem('&Test1', 0, True, True, nil, 0, ''),
NewItem('&Test2', 0, True, True, nil, 0, '')]));
MainMenu1.Items[0].Add(NewLine);
with NewPopupMenu(self, 'ole', paleft, true,
NewItem('&Test1', 0, True, True, nil, 0, ''),
NewItem('&Test2', 0, True, True, nil, 0, '')]) do
Popup(10, 10);