Sender object definition in Delphi!
1. Sender definition:
Each event processing contains at least one sender parameter. For example:
Procedure tform1.button1click (Sender: tobject );
Begin
...
End;
Sender indicates the control that calls the tform1.button1click process. Because sender is tobject, any object can be assigned to sender.
When you click button1, A button1click event will be generated. The system will pass button1 to the button1click process as a parameter, that is, sender.
2. Sender usage:
<1>. because sender represents the control in the process of calling, you can directly use it as the control, but if you want to use attributes, it is best to write it (sender as control name ). control property: =... for example:
Procedure tform1.edit1click (Sender: tobject );
Begin
With sender as tedit do // use sender as the tedit class, and the as operator is type conversion.
Begin
Text: = 'hello ';
End;
End;
<2> If the same process is handled in two events, you can use sender to overwrite the same process. For example:
Procedure tform1.button1click (Sender: tobject );
Begin
Do same .....;
If sender = button1 then
Do something ....;
If sender = button2 then
Do other ....;
End;
Procedure tform1.button2click (Sender: tobject );
Begin
Button1click (button2 );
End;