How can I change the behavior of the event handler based on which TAction triggered it?

I have some menu items where this action is:

procedure TMISMainFrm.ActiSalesInvoiceExecute(Sender: TObject); begin if CheckMdiList('Sales Invoice') then BEGIN SalesInvFrm := tSalesInvFrm.Create(Self,0,UserIdNo,1,1); SalesInvFrm.Show; END; end; 

The above action can be called from several places, but the second parameter (0) can change. How to pass the required parameter so that I don’t have to recode the procedure?

+4
source share
1 answer

One simple approach commonly used is to set the Tag property of an action. Obviously, for each action this should be different. Then you change the execution handler as follows:

 procedure TMISMainFrm.ActiSalesInvoiceExecute(Sender: TObject); begin if CheckMdiList('Sales Invoice') then BEGIN SalesInvFrm := tSalesInvFrm.Create(Self,(Sender as TAction).Tag,UserIdNo,1,1); SalesInvFrm.Show; END; end; 
+7
source

All Articles