Friday, 30 August 2013

Creating a popup menu at runtime

Creating a popup menu at runtime

I'm trying to simply create a popup menu (or context menu), add some items
to it, and show it at the mouse location. All the examples I have found
are doing this using the designer. I'm doing this from a DLL plugin, so
there is no form/designer. The user will click a button from the main
application which calls the execute procedure below. I just want something
similar to a right click menu to appear.
My code obviously doesn't work, but I was hoping for an example of
creating a popup menu during runtime instead of design time.
procedure TPlugIn.Execute(AParameters : WideString);
var
pnt: TPoint;
PopupMenu1: TPopupMenu;
PopupMenuItem : TMenuItem;
begin
GetCursorPos(pnt);
PopupMenuItem.Caption := 'MenuItem1';
PopupMenu1.Items.Add(PopupMenuItem);
PopupMenuItem.Caption := 'MenuItem2';
PopupMenu1.Items.Add(PopupMenuItem);
PopupMenu1.Popup(pnt.X, pnt.Y);
end;

No comments:

Post a Comment