Delphi IDE (239)
Windows with Delphi (38)
About this site
Links to us
What is 'Sender:TObject'?
4 comments. Current rating: (3 votes). Leave comments and/ or rate it.
I would like to know what information is contained in 'Sender' and how I get at it.
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
- You can of course also check for a particular component:
if Sender = TButton1 then
else if Sender = TListBox1 then