Page 1 of 1

how to add items to pop-up menu

Posted: Sat Feb 23, 2008 9:30 am
by toolwiz
I asked this earlier but I don't think it was answered completely.

In the Actions Demo, you can right-click on the SRV area and a context menu appears. It's generated by the action framework. I'm not sure if it's one of the popup menus on the form, or if it's generated dynamically.

I added some buttons to the toolbar and created actions for them.

How can I get one of them to appear in the right-click menu? (I don't know where the popup is generated, so I don't know which OnPopup method to hook into.)

Thx
-David

Posted: Sun Feb 24, 2008 5:08 pm
by Sergey Tkachenko
You cannot add items in TRVAPopupMenu at designtime, you must do it at runtime, in code.

This menu is recreated (existing items are deleted, new items are added) every time before displaying.

First, the default menu items are added. Next, TRVAPopupMenu.OnPopup event occurs.
You can add new items in TRVAPopupMenu.OnPopup event.

Posted: Sun Feb 24, 2008 6:53 pm
by toolwiz
We're going in circles here. I know how to use the OnPopup event. I assume it needs to be done at run-time. I'm just not sure which one to hook into. There are two popups on the Actions Demo form, but from what I can tell, neither one of them is the one that's used when you right-click on the SRV edit box. How do I find the one that IS used and hook into it without disabling it? It seems to be getting created dynamically. Where?

Thanks
-David

Posted: Mon Feb 25, 2008 9:50 am
by Sergey Tkachenko
There is only one TRVAPopup menu in this demo (RVAPopupMenu1), and it is assinged to SRichViewEdit1.PopupMenu property. Use it.
For example, this code adds "Background..." command as the last item:

Code: Select all

procedure TForm3.RVAPopupMenu1Popup(Sender: TObject);
var mi: TMenuItem;
begin
  mi := TMenuItem.Create(RVAPopupMenu1);
  mi.Action := rvActionsResource.rvActionBackground1;
  RVAPopupMenu1.Items.Add(mi);
end;
The second popup menu in this demo (pmFakeDropDown) is assigned to DropDownMenu property of combo-toolbutton for table insertion. This menu is empty and never displayed, but its OnPopup event is used to display a table-size window.

Posted: Mon Feb 25, 2008 6:27 pm
by toolwiz
Great! Thank you very much!

-David

How to implement additions to popup menu at runtime

Posted: Tue Jan 11, 2011 7:53 pm
by futuremode
I am a newbie and was having trouble implementing the addition of actions to the popup menu so they appeared at runtime. Where do I install it in the app.

Posted: Tue Jan 11, 2011 8:15 pm
by Sergey Tkachenko
Do you want to add action in TPopupMenu or in TRVAPopupMenu?

To TRVAPopupMenu

Posted: Wed Jan 12, 2011 7:41 am
by futuremode
Sergey Tkachenko wrote:Do you want to add action in TPopupMenu or in TRVAPopupMenu?
To TRVAPopupMenu. I have created an action and applied it to the main menu and a tool button but am having trouble with the right click popup menu in RichViewEdit1 of your demo Rich View Actions app.

I want users to right mouse click which opens up a list so they select data merge tags and drop them into the RichViewEdit1 doc. The main menu item and button are working fine.

Posted: Thu Jan 13, 2011 7:09 pm
by Sergey Tkachenko
Please read this topic from the beginning.
It explains how to add items in TRVAPopupMenu.

Briefly: you cannot do it at designtime because TRVAPopupMenu clears all items before displaying, and then it recreates itself.
To add your item in this menu, use OnPopup event. The example is above in this topic.

Thanks Sergey

Posted: Fri Jan 14, 2011 9:03 am
by futuremode
I have only been programming with Delphi for around six months so it is a steep learning curve for me. I have it all working now.