Definitions of sender objects in Delphi

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.