Mega Code Archive

 
Categories / Delphi / Examples
 

What is sendertobject

Question: I would like to know what information is contained in 'Sender' and how I get at it. Answer: Normally, Sender is the object that called the routine. So if you have an event handler, that is connected to a TButton, it is the button. But if it is connected to more than one button, then it is the button that caused the event. - If you know it is a button,you can use 'as': ShowMessage((Sender as TButton).Caption); - You can check the type of Sender with 'is': if Sender is TButton then ShowMessage(TButton(Sender).Caption); - You can of course also check for a particular component: if Sender = TButton1 then ... else if Sender = TListBox1 then ...