I want to set an event OnClick
to all TMenuItems
on the screen to do what the event currently does, and another few lines of code. I am currently using Delphi 5
For example, say that I have a TMenuItem
with the code:
procedure TdesktopForm.MenuFoo1Click(Sender: TObject);
begin
ShowMessage(TComponent(Sender).Name)
end;
and I also have the following procedure:
procedure TdesktopForm.bar;
begin
ShowMessage('extra')
end;
And I want to everytime I click the TMenuItem the program show the TMenuItem's name and also the 'extra' message.
The example shown is just a demonstration of my problem, as in the real software I have over 300 menu items, I want to do this generically, so I won't have to add extra lines of code to all current menu clicks, nor add them when I add new menu items. The order of execution (between the menu click and the extra block of code) doesn't matter.
I tried using TActionList
but I couldn't retrieve the object triggering the action, hence, I can't print it's name. I tried using ActiveControl
but it always return the focused currently focused object, not the actual menu that I clicked. And also, the TAction
execute event overwrites my TMainMenu.OnClick
event
TAForm.ActionList1Execute(Action: TBasicAction; var Handled: Boolean); begin Showmessage(Action.ActionComponent.Name); end;
orprocedure TAForm.AllActionsExecute(Sender: TObject); begin Showmessage(TAction(Sender).ActionComponent.Name); end;
– bummi Apr 2 '19 at 13:54ActionComponent
but this property is inexistant in myTAction
. I would guess it was introduced in a newer version than the one i'm using – Rodolfo Donã Hosp Apr 2 '19 at 14:00