Delphi: Easy Concept

zhaozj2021-02-11  217

First, the difference between Owner and Parent:

The Parent property is a package container for a component that can only be displayed and moved within this range. Examples are as follows:

(1) On the form of Form1, put a panel1, and pull the Panel1,

(2) Put a Button1 on Panel1;

(3) Place a Button2 on Form1.

Now if you move Panel1, Button1 moves with Panel1 because the Parent of Button1 is Panel1. Now move Button2 on Panel1, move Panel1 again, button2 does not move, this is because Button2's Parent is Form1. In addition to in the form design, attention should be aware that the part of the component is, when dynamically created the component, it should also indicate the PARENT of the component, such as continued operation in the above example:

1) Procedure TFORM1.BUTTON2CLICK (Sender: TOBJET);

2) VAR

3) Button: tbutton;

4) Begin

5) Button: tbutton.cerate (Self);

6) Button.parent = panel1;

7) Button.lleft = 0;

8) Button.top = 0;

9) Button.caption: = 'ok';

10) end;

When pressing Button2, a Button will be created on Panel1, and if you change the sixth sentence to Button.Parent: = Self; press Button2, you will create a button on Form1. If you delete the 6th sentence, press button2, nothing will happen, because the creation method cannot know where the component should be displayed.

The Owner property is the owner of the component, which is responsible for the creation and release of the component. As in the above example, the owner of all components on the system default form is a form, and the owner of the form is Application. Incidentally, the Create method should have parameters representing the member owner. As in the above example, the component owner is a form, that is, Self.

The Parent attribute and the Owner property are attributes of the running phase, which can only be set at the runtime phase.

Second, the difference between SELF and SENDER:

In the event handler parameter table, at least one parameter sender contains at least a member that triggers the event handler. As in the above example, Sender refers to Button2, with the sender parameter, allowing multiple components to share the same event handler Such examples:

Procedure TFORM1.BUTTONCLICK (Sender: TOBJECT);

Begin

If sender = button1 Then

Label1.caption: = 'Flowers in front of the court

'Else label2.caption: =' Wang Sheng Yunnun Yunshu '

END;

In this example, Button1, button2 share the ButtonClick event handler.

SELF means which class is the program range in which the Delphi is programmed within the form range, so Self is the form, if you write a class or a component, Self refers to the class or component. . We can see that SELF is representative of which component, the Self representative '.'. In the first example, Self represents TFORM1. Also note that Self can only be used in a class method, instead of using in a process or function, as used as the following example is wrong:

Function A1 (B: Integer): Integer;

Begin

......

Button: = TButton.create (Self); ......

END;

Third, the difference from ClientHeight and Height, ClientWidth and Width:

For general components, Height is ClientHeight, Width is ClientWidth, and for a form, Height is a height of the title bar, while ClientHeight refers to the height of the form workspace. Similarly, ClientWidth is the width of the specified form workspace.

From the above statement, understand the difference between Ower and Parent, Self and Sender, ClientHeight, and Height, ClientWidth, and Width, are important to program the correct programming in Delphi.

转载请注明原文地址:https://www.9cbs.com/read-3921.html

New Post(0)