2011. január 24., hétfő

Create an item in a TActionMainMenuBar at runtime

Problem/Question/Abstract:

How to create an item in a TActionMainMenuBar at runtime

Answer:

{ ... }
var
iItem: TActionClientItem;
iAction: TAction;
begin
iAction := TAction.Create(myActionManager); {Create the Action for the item}
iItem := myActionManager.ActionBars[0].Items.Add; {Add item to menu with the index 0}
iAction.Caption := 'My Item';
iItem.Action := iAction; {Assign Action to the item}
end;

To create a submenu item, do:

{ ... }
var
iItem: TActionClientItem;
iAction: TAction;
begin
iAction := TAction.Create(myActionManager);
iItem :=
myActionManager.ActionBars[0].Items[MyFirstMenu].Items[MyFirstSubmenu].Items.Add;
iAction.Caption := 'My item in the submenu';
iItem.Action := iAction;
end;


Nincsenek megjegyzések:

Megjegyzés küldése