Delphi .NET (2) Database (71) Delphi IDE (90) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280)
Exchange Links About this site Links to us 
|
What is 'Sender:TObject'?
3 comments. Current rating: (3 votes). Leave comments and/ or rate it.
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
...
Comments:
|