How to add a standard action to the ActnPopup.TPopupActionBar component at runtime?

I am using the ActnPopup.TPopupActionBar component and I want to add a couple of standard actions such as TFileOpen , TFileOpenWith and so on. The question is, how can I add these actions at runtime to TPopupActionBar?

+6
source share
1 answer

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.

+6
source

Source: https://habr.com/ru/post/910548/


All Articles