[DUG] How to find parameters of an Action Menu created at runtime

Errol Anderson errol.anderson at gsds.co.nz
Thu Dec 21 17:49:05 NZDT 2017


Thanks.  It appears that Delphi doesn't keep a record of which control
initiates the OnExecute method.  I have copied some comments from
http://www.delphigroups.info/3/96/1480.html 

 

> Is the Sender parameter for a TAction::OnExecute the  TAction or is it the
Object say a TMenuItem that 'called' the action? 

It is the Action itself

> how can I determine what control initiated this OnExecute method? 

You can't, short of enumeration through all of your components looking to
see which ones have their Action property associated with the given Action.
Even that may not be good enough if you have multiple objects using the same
Action.

Actions are designed as an abstraction layer that can be assigned to
multiple objects without caring what they actually are.  Actions don't keep 
track of the actual objects that link to them.  What they do keep track of,
however, is a list of TBasicActionLink instances.  Each object that wants to
support an Action property has to instantiate its own internal
TBasicActionLink instance which is used as the communication link between 
itself and the Action.  There's no way to know which object caused the
Action to trigger, as the Action could be linked to multiple objects, and 
the object pointer is not passed around during the Execution process.  The
object merely requests that the Action execute itself. 

So it looks like I cannot easily use Action Menus to provide variable menus,
dependent on the data in the database, and will have to use some messy
mixture of Action Menus and Popup menus.  

I must agree with the comments of Scott Metzge in delphigroups, namely:

". that makes TActions a lot less useful than I thought they were."  

If anyone has any ideas how to find which item was clicked, I would be very
grateful.

Regards

Errol

 

 

 

 

 

From: David O'Brien [mailto:Dave at iccs.co.nz] 
Sent: Thursday, 21 December 2017 5:10 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

 

No worries. I didn't actually try it, just a thought.

 

"If an action band contains a TCustomizeBandAction standard action, the user
of the application can change this property. Because the caption can be
changed at runtime, the default caption that will be used, should be set in
the action itself and not in the
<http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate
2/EN/html/delphivclwin32/ActnMan_TActionClientItem.html> TActionClientItem
object."

 

From: delphi-bounces at listserver.123.net.nz
<mailto:delphi-bounces at listserver.123.net.nz>
[mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Errol Anderson
Sent: Thursday, 21 December 2017 2:01 pm
To: 'NZ Borland Developers Group - Delphi List'
<delphi at listserver.123.net.nz <mailto:delphi at listserver.123.net.nz> >
Subject: Re: [DUG] How to find parameters of an Action Menu created at
runtime

 

Hi David

 

Thanks for your suggestion.  Unfortunately it raises the following error:



 

Because there may be multiple items with the same action but different
captions, I figured I had to pick the item caption, not the action caption.


 

I have tried creating one or multiple items at designtime as a test, but I
get the same results every time - namely TActionClientItem(Sender).Caption
returns a null string, and TAction(TActionClientItem(Sender).Action).Caption
fails.  It appears that TActionClientItem does not act like TMenuItem which
is very disappointing.

 

Best regards

 

Errol

 

From: David O'Brien [mailto:Dave at iccs.co.nz] 
Sent: Thursday, 21 December 2017 9:58 AM
To: NZ Borland Developers Group - Delphi List <delphi at listserver.123.net.nz
<mailto:delphi at listserver.123.net.nz> >
Subject: Re: [DUG] How to find parameters of an Action Menu created at
runtime

 

The Sender will be the menu item. Try   TAction(TActionClientItem
(Sender).Action).Caption.

 

From: delphi-bounces at listserver.123.net.nz
<mailto:delphi-bounces at listserver.123.net.nz>
[mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Errol Anderson
Sent: Thursday, 21 December 2017 9:47 am
To: delphi at listserver.123.net.nz <mailto:delphi at listserver.123.net.nz> 
Subject: [DUG] How to find parameters of an Action Menu created at runtime

 

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 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20171221/430d6877/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 2339 bytes
Desc: not available
Url : http://listserver.123.net.nz/pipermail/delphi/attachments/20171221/430d6877/attachment.png 


More information about the Delphi mailing list