Author: Jonas Bilinkevicius
How to create an item in a TActionMainMenuBar at runtime
Answer:
1 { ... }2 var3 iItem: TActionClientItem;
4 iAction: TAction;
5 begin6 iAction := TAction.Create(myActionManager); {Create the Action for the item}7 iItem := myActionManager.ActionBars[0].Items.Add; {Add item to menu with the 8 index 0}9 iAction.Caption := 'My Item';
10 iItem.Action := iAction; {Assign Action to the item}11 end;
To create a submenu item, do:
12 { ... }13 var14 iItem: TActionClientItem;
15 iAction: TAction;
16 begin17 iAction := TAction.Create(myActionManager);
18 iItem :=
19 20 myActionManager.ActionBars[0].Items[MyFirstMenu].Items[MyFirstSubmenu].Items.Add;
21 iAction.Caption := 'My item in the submenu';
22 iItem.Action := iAction;
23 end;