[DUG] How to find parameters of an Action Menu created at runtime
Errol Anderson
errol.anderson at gsds.co.nz
Fri Dec 22 16:58:53 NZDT 2017
Hi Jeremy,
Thanks for this – it works brilliantly, and so easy to implement. I thought it would be necessary to use CustomActionMenuBar, but had no idea how to do this. I clearly have a bit more to learn in the Delphi universe.
Have a great Christmas and the best new year.
Regards
Errol
From: Jeremy North [mailto:jeremy.north at gmail.com]
Sent: Thursday, 21 December 2017 8:25 PM
To: NZ Borland Developers Group - Delphi List <delphi at listserver.123.net.nz>
Subject: Re: [DUG] How to find parameters of an Action Menu created at runtime
Hi Errol,
If the items are on the TActionMainMenuBar component then you can do the following:
type
TCustomActionMenuBarAccess = class(TCustomActionMenuBar);
In the Action Execute you can then do:
if TCustomActionMenuBarAccess(ActionMainMenuBar1).FSelectedItem <> nil then
ShowMessage('Selected Item: ' + TCustomActionMenuBarAccess(ActionMainMenuBar1).FSelectedItem.Caption);
where ActionMainMenuBar1 is the name of the TActionMainMenuBar component on the form.
If the items are created on a toolbar, then you can use the TAction(Sender).ActionComponent property as the TAction is the sender in these cases.
cheers,
Jeremy
On Thu, Dec 21, 2017 at 7:47 AM, Errol Anderson <errol.anderson at gsds.co.nz <mailto:errol.anderson at gsds.co.nz> > wrote:
My program creates Action Menu items at runtime, with the caption of each item set to a value returned by a database query. The OnExecute procedure is the same for all items.
When I click on an item, I need to obtain the item caption for the OnExecute procedure, to use in another query. I have tried the following (analogous to TMenuItem for a popup menu):
sCaption := TActionClientItem(Sender).Caption;
However, this always returns an empty string. I have searched the web and the Delphi Help to no avail. I am aware that Caption is a published property, but the public property Index also fails.
I presume I am doing something wrong here, but cannot figure out what. Any help appreciated.
Regards
Errol Anderson
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at listserver.123.net.nz <mailto:delphi at listserver.123.net.nz>
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at listserver.123.net.nz <mailto:delphi-request at listserver.123.net.nz> with Subject: unsubscribe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20171222/94c8d085/attachment.html
More information about the Delphi
mailing list