I would try something like this:
procedure TForm1.Button1Click(Sender: TObject); var MenuItem: TMenuItem; Action: TCustomAction; begin MenuItem := TMenuItem.Create(PopupActionBar1); Action := TFileOpen.Create(PopupActionBar1); Action.Caption := '&Open...'; Action.ShortCut := 16463; MenuItem.Action := Action; PopupActionBar1.Items.Add(MenuItem); MenuItem := TMenuItem.Create(PopupActionBar1); Action := TFileOpenWith.Create(PopupActionBar1); Action.Caption := 'Open with...'; MenuItem.Action := Action; PopupActionBar1.Items.Add(MenuItem); end;
And where did I get the values โโof Caption and ShortCut? Good question. This is from the action list component editor. You can get them by adding standard actions to your action list and looking at your form source code. There you will see definitions of your actions, for example:
object FileOpen1: TFileOpen Category = 'File' Caption = '&Open...' Hint = 'Open|Opens an existing file' ImageIndex = 7 ShortCut = 16463 end
And since you do not need a hint for the popup menu (for the popup menu item?), Category (for the list of actions) and ImageIndex (you can define your own set of images, so your indexes may differ), you can leave them. In fact, you can leave it all, the action will be performed even so (based on the class that you will use), but you would not have a title or label.
TLama source share