Tutorials to .com

Tutorials to .com » Software » Delphi » Delphi in the attributes of property (for beginner delphi)

Delphi in the attributes of property (for beginner delphi)

Print View , by: iSee ,Total views: 26 ,Word Count: 1361 ,Date: Sun, 23 Aug 2009 Time: 4:09 AM

delphi in the attributes of property (for beginner Delphi)

Propery In Delphi

office: office "/>


For delphi beginner, there are object-oriented knowledge and java or programming experience to read vc.

A common attribute

We delphi class often able to see this kind of code: propert property attribute of the type of read string 1 write string 2

Here the name attribute may be different. This format are: property attributes were read string 1 write string 2

My property Left: Integer read FLeft write SetLeft; for example, it is Tcontrol attributes, you can controls documents found. Left is a property of type Integer. Read access to the stated variables to access the variable or method, write to revise the stated variables, or variable access methods. Note: can be variable, it can be, I tell you later how this is going on. Here it is a variable called FLeft. For the purpose of packaging, they will generally be placed on such private intermediate variables, and it turned out, in private, we can find

FLeft: Integer this code (out of the habit of naming, we named this variable plus the property name in front of a capital F). So when you read the property, the fact is that your visit to Fleft value. So you can write some methods to modify fleft, indirectly, to amend the value of the left. Then we look at SetLeft, here it is a way to (ask me how did you know? Name or look at the rules, usually in front of the property name together with the Set), will usually go on in private, we have to verify that we in the private see that stated:

procedure SetLeft (Value: Integer);

And the following code:

procedure TControl.SetLeft (Value: Integer);


SetBounds (Value, FTop, FWidth, FHeight);

Include (FScalingFlags, sfLeft);


If you wrote the following code to change the left: control1.left: = 23, then the program calls a function SetLeft (23), SetBounds function is to change the region, here you will understand the benefits of the package it, every time you change the left when it will be left under the new change the size of the region, this function also changes the size of Fleft, please refer to the source code SetBounds.

procedure TControl.SetBounds (ALeft, ATop, AWidth, AHeight: Integer);


if CheckNewSize (AWidth, AHeight) and

((ALeft <> FLeft) or (ATop <> FTop) or

(AWidth <> FWidth) or (AHeight <> FHeight)) then


InvalidateControl (Visible, False);

FLeft: = ALeft;

FTop: = ATop;

FWidth: = AWidth;

FHeight: = AHeight;





if not (csLoading in ComponentState) then Resize;



This looks just outside on the assignment operator to change the value of the property. Read and write can be variable, or function, depending on your design. Of course you can write: propert property attribute of the type of read variables 1 write variable 2. Variable 1 and variable 2 can be the same. You can also attribute this propert property of the type of read method of 1 write Method 2. No matter how you mix. However, attention should be paid to 2:00:

1. Named the best in accordance with customary rules, the easier to read.

2. If it is variable, then the type and attributes to the type of agreement, if it is, then the entrance of the parameters and attributes to the type of agreement.

Second incident Tevent property

We often use components of the event attributes, such as click events, but it is difficult to see the face of it is how to call it, how it is triggered. I'll give you the following answer.

Property manager in the object inspector to see the right side of the corresponding event page onclick of a method name. In fact, we can do to a corresponding component of the incident from the previous method. Form as an example of a Form1. OnMouseDown: = 'your way'. Attention to methods of parameters about the entrance, this is (Sender: TObject)

We have a tcontrol as an example, we find this code:

property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown; with the above similar, but there is a special type, TNOtifyEvent, is a type of event, we find it stated:

TMouseEvent = procedure (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer) of object;

Can see that it is actually a function, but the blue part of the entrance to the limited parameters. Then we assign Form1. OnMouseDown: = 'your way', it corresponds to the OnMouseDown method. And then we just write a function to intercept mouse messages, in which, directly or indirectly, call FonMouseDown, news and so put up a deal with the corresponding function. Here it is the rise of indirect calls are more speaking relatively time-consuming, involving Message type, suggest that you look at the book under the Li.

Indirectly attached to the process of the following call, in fact, a lot of information but also indirectly at the time of the call, not a one out: (

procedure WMRButtonDblClk (var Message: TWMRButtonDblClk); message WM_RBUTTONDBLCLK; / / function to intercept messages

procedure TControl.WMRButtonDblClk (var Message: TWMRButtonDblClk);



DoMouseDown (Message, mbRight, [ssDouble]);


procedure DoMouseDown (var Message: TWMMouse; Button: TMouseButton;

Shift: TShiftState);

procedure TControl.DoMouseDown (var Message: TWMMouse; Button: TMouseButton;

Shift: TShiftState);


if not (csNoStdEvents in ControlStyle) then

with Message do

if (Width> 32768) or (Height> 32768) then

with CalcCursorPos do

MouseDown (Button, KeysToShiftState (Keys) + Shift, X, Y)


MouseDown (Button, KeysToShiftState (Keys) + Shift, Message.XPos, Message.YPos);


procedure MouseDown (Button: TMouseButton; Shift: TShiftState;

X, Y: Integer); dynamic;

procedure TControl.MouseDown (Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);


if Assigned (FOnMouseDown) then FOnMouseDown (Self, Button, Shift, X, Y);



If you write their own category, you will find how to do so is to facilitate and not to java to write getleft, setleft, and then the text on the private, the access and modification to call in different ways, and the delphi you just call contol1.text to visit, control1.text: = 'a string' to modify its value.

When dealing with information, the base class to onclick, onmousedown attribute affirm such as protected, if you want to use, can be affirmed to be published on the inside in the object inspector, and then write a convenient approach, you can not open, and ctreate function in the assignment to it, and do not like java, the listener is less complex to write.

Delphi Tutorial Articles

Can't Find What You're Looking For?

Rating: Not yet rated


No comments posted.