[SOLVED] Assigning Action to ToolButton lazarus / 31-LCL ---------------------------------------------------------------------- egsuh · 2021-03-30 05:50 (The title) removes pre-defined Image index and Hint content of TToolButton. Assigning Onclick event does not. And the event handler's Sender is TAction, when ToolButton's Action property is defined. Are these normal? ---------------------------------------------------------------------- devEric69 · 2021-03-30 07:52 Hello, Basically, AFAIK, the properties of a TAction should be defined first, and then when a TControl is connected to such an TAction, the common properties among TAction (and its connecting TControl) should diffuse (from TAction towards TControl) and replace those of the connecting TControl. Nevertheless, it's always possible to override those of a connected TAction by rewriting them in their property editor. This is the normal behavior. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-03-30 20:33 Hey egsuh, A TAction is the perfect way to have code placed in only one place and easily assigned to other components. Lets say, for example, that you have: A menu entryA Toolbar ButtonA button And you want all those 3 to have the same code executed upon being chosen/clicked, but apart from that you want them to have the same Hint, ShortCut, Caption, Image, etc... Well, the best way to do it is by filling all those properties on the TAction. Then when you assign a TAction to your component, all those properties get populated from the TAction. Now, this doesn't mean that the components is now locked to the TAction, it just means that all properties have been copied to it. If you want to have them be different from the TAction, just fill them out after you assign the TAction. Hope that helps! Cheers, Gus ---------------------------------------------------------------------- egsuh · 2021-03-31 05:40 QuoteA TAction is the perfect way to have code placed in only one place and easily assigned to other components. Yes, I know that. Just problem is I have no way to know from where the call of the action come from. I tried to share the same action between several buttons but behave slightly differently. I needed to let the action's OnExecute procedure know where the call comes from, but once I assign Action property of a button then all the calls were from TAction.  So I directly assigned actMyActionExecute procedure to the button's OnClick events. In this way, I could check the Sender. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-03-31 11:38 Hey egsuh, Quote from: egsuh on March 31, 2021, 07:40:37 amYes, I know that. Just problem is I have no way to know from where the call of the action come from. I'm afraid that that's not entirely correct: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // Form sectionbtnSomeAction: TButton;btnSomeAction1: TButton;mnuSomeAction: TMenuItem;tbtnSomeAction: TToolbarButton; procedure TForm1.actSomeActionExecute(Sender: TObject);begin  If Sender = btnSomeAction then  begin    // This comes from the Button  end;  If Sender = btnSomeAction1 then  begin    // This comes from the Button 1  end;  If Sender = mnuSomeAction then  begin    // This comes from the Menu Item  end;  If Sender = tbtnSomeAction then  begin    // This comes from the Toolbar Button  end;end; Does that help? Cheers, Gus ---------------------------------------------------------------------- egsuh · 2021-03-31 11:49 QuoteI'm afraid that that's not entirely correct: I explained that. If defined as follows, Sender is always TAction.    btnSomeAction.Action:= actSomeAction;    btnSomeAction1.Action:= actSomeAction;    mnuSomeAction.Action:= actSomeAction;    tbtnSomeAction.Action:= actSomeAction; But I can discern Sender if I define as follows:    btnSomeAction.OnClick:= actSomeActionExecute;    btnSomeAction1.OnClick:= actSomeActionExecute;    mnuSomeAction.OnClick:= actSomeActionExecute;    tbtnSomeAction.OnClick:= actSomeActionExecute; ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-03-31 12:05 Hey egsuh, Wow, I'm really sorry, egsuh, for such a patronizing message!! I was under the impression that the OnExecute would carry the caller's object. I even went and tested it. That's how far I was up my own arse You are completely right, if you want to know who's the caller, the OnExecute of the TAction is completely useless!! And again, my deepest apologies for being such and arse!! Cheers, Gus ---------------------------------------------------------------------- wp · 2021-03-31 12:32 But when you press F1 on "TAction" (or better: Ctrl+Click to open the implementing unit) and then navigate up the inheritance you'll see at the most elemental action, TBasicAction, that there is a public property Actioncomponent (TComponent) for which the help file says: "Return the component that initiates the action." So, please run at attached demo and see that this is exactly what you are looking for. OnExecute is not useless. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-03-31 12:37 Hey WP, Quote from: wp on March 31, 2021, 02:32:25 pm TBasicAction, that there is a public property Actioncomponent (TComponent) for which the help file says: "Return the component that initiates the action." WP, YOU DA MAN!! That's why I'm the ignorant fool making such generalised false statements. Thanks for the lesson!! Cheers, Gus