Differences between self and sender in Delphi)

Source: Internet
Author: User

In event processingProgramThe parameter table contains at least one sender parameter, which represents the component that triggers the event processing program. In the preceding example, sender refers to button2 and has the sender parameter, multiple components can share the same event handler, as shown in the following example:
Procedure tform1.buttonclick (Sender: tobject );
Begin
If sender = button1 then
Label1.caption: ='
'Else label2.caption: = 'Hope the cloud is on the cloud and the cloud is Shu ′
End;

In this example, button1 and button2 share the buttonclick event handler.

Self refers to the class in which the program scope is compiled, and Delphi mostly programs in the form scope. Therefore, self refers to the form. If you are writing a class or component, self indicates the class or component. In the declaration of a function or process, we can see which component self represents, that is, the component before '.'. For example, in the first example, self represents tform1. In addition, it should be noted that self can only be used in class methods, but not in procedures or functions. The following example is incorrect:
Function A1 (B: integer): integer;
Begin
......
Button: = tbutton. Create (Self );......
End;

Iii. Differences between clientheight and height, clientwidth and width:

For general components, height is clientheight, width is clientwidth, and for a form, height is the height including the title bar, And clientheight is the height of the form workspace. Similarly, clientwidth specifies the workspace width of the form.

It can be seen from the above statement that it is important to understand the differences between ower and parent, self and sender, clientheight and height, clientwidth and width for correct programming in Delphi.

Inadvertently accessing the internet in the csdn Forum shows a very vivid explanation: You can refer

Method, event, sender, tobject, self

You are a human (tobject), you have your own gender, age, height, etc. (attributes), you will also climb and walk (methods), you also have your emotions, thoughts, when others say hello, you are very happy. When you say you are bad, you will be very frustrated (events). One day you hear yourself (Self) someone else (sender) you will be very upset when it comes to your thoughts (events) that your girlfriend is so beautiful (events handle external responses)

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.