dummzeuch 1505 Posted October 15, 2019 Can somebody explain to me what TForm.Action is for? And how it can be used? The OLH is here, but it does not specifically talk about TForm: http://docwiki.embarcadero.com/Libraries/Rio/en/Vcl.Forms.TForm.Action It refers to an example http://docwiki.embarcadero.com/CodeExamples/Rio/en/TFormAction_(Delphi) which I also don't understand. From the example I gather that TForm.Action is not assigned by default, but when and by which mechanism is it executed? It's not that I need it, I just came across this property for the first time (it has existed for over a decade). Share this post Link to post
Anders Melander 1782 Posted October 15, 2019 I don't ever use the OnExecute handler, but I generally use the OnUpdate handler to update controls that does not support actions themselves. I guess one could also use it to control TForm.Enabled but I've never had a need for that. The forms OnUpdate handler is also convenient when modernizing applications that were written without TActionList. These tend to have a single method that contains all the UI update logic. I move this logic into the OnUpdate handler, review and remove all the calls to the old update method and then start migrating the logic to individual actions. I mostly end up with some logic that can't be handled by actions and so it stays on the forms OnUpdate handler. 1 Share this post Link to post
Cristian Peța 103 Posted October 15, 2019 "Vcl.Forms.TForm.Action inherits from Vcl.Controls.TControl.Action" It's for buttons and menu items. You select an action defined in a TActionList object (centralized actions). It's strange to have this for TForm but this is like in FMX where any control can be a container for any control. Share this post Link to post
Anders Melander 1782 Posted October 15, 2019 1 minute ago, Cristian Peța said: It's for buttons and menu items. I think the question (and my answer) is specifically about what TForm.Action is for. Not what TControl.Action in general is for. The Action property is explicitly published by TForm so it's not by accident that it's visible in the property inspector. 1 Share this post Link to post
Cristian Peța 103 Posted October 15, 2019 I see that when you click on a form their Action is executed. Action property was probably published for someone that will find something useful in this. Share this post Link to post
FredS 138 Posted October 15, 2019 2 hours ago, dummzeuch said: came across this property for the first time create an action aiOnIdle using the forms caption link it to the form name the update event OnIdle Then use that event as needed, beware the OnIdle event won't fire when a modal dialog is up. Unlike the TActionList.OnUpdate event this one will fire as long as the form is enabled. Share this post Link to post
Anders Melander 1782 Posted October 15, 2019 TActionList.OnUpdate (and OnExecute) is different in that these fire once for every action in the actionlist. Share this post Link to post
Guest Posted October 15, 2019 6 hours ago, Cristian Peța said: Action property was probably published for someone that will find something useful in this. I agree! So the question still remains. Who would want this, in what context? What is the benefit compared to a much more legible "OnClick" implementation? Share this post Link to post
Remy Lebeau 1394 Posted October 15, 2019 51 minutes ago, Dany Marmur said: I agree! So the question still remains. Who would want this, in what context? What is the benefit compared to a much more legible "OnClick" implementation? The same could be asked for any UI control that has a published Action property and a published OnClick (or other actionable) event. One reason is code reuse, the same Action object can be assigned to multiple controls, even the Form itself. For instance, Actions are commonly shared with menu items and other UI controls that invoke the same actions. Another use would be sharing common properties with multiple controls (Enabled, Visible, etc) so you can update 1 property and have it propagate to multiple controls automatically. 2 Share this post Link to post
dummzeuch 1505 Posted October 16, 2019 (edited) So, the Action is executed when the user clicks on the form? Edited October 16, 2019 by dummzeuch Share this post Link to post
Guest Posted October 16, 2019 14 hours ago, Remy Lebeau said: Another use would be sharing common properties with multiple controls (Enabled, Visible, etc) so you can update 1 property and have it propagate to multiple controls automatically. A point indeed. Share this post Link to post
Uwe Raabe 2057 Posted October 16, 2019 Another advantage of actions and action lists is that they can reside on a datamodule, which can be used in a VCL and a FMX application. Thus the same action logic can be used, which might have to be duplicated otherwise. 2 Share this post Link to post
Edwin Yip 154 Posted October 16, 2019 The same quick question once occurred to me, I concluded I don't have a use for it, and I just ignore it :) Share this post Link to post
dummzeuch 1505 Posted October 16, 2019 I'm not questioning the advantages of actions in general, just that of an action property in TForm. I still haven't understood what that particular one can be used for. Share this post Link to post
Remy Lebeau 1394 Posted October 16, 2019 44 minutes ago, dummzeuch said: I'm not questioning the advantages of actions in general, just that of an action property in TForm. I still haven't understood what that particular one can be used for. I don't understand what is confusing about it. Actions have several properties and events that apply to Forms just as they do to any other UI control. Share this post Link to post