Parent:=Self; // Fonnl
SetBounds(X,Y,W,H); // (X- Left, Y- Top. W- Width, H - Height)
Name:='NewButton'; // Caption NewButton
Visible:=True;
... //
End;
, , Self, , Self - , . Self VMT.
- . , . , . . :
. , . , "".
. , , , . , , , , .
. , , , - . , , , ..
. , , . , .
( ) (information hiding). , .
, , , , . , . : Private,
|
|
Protected, Public, Published.
, ,
Public.
:
Type
< ca>=Class[(< >}]
Private //
< >
Protected //
< >
Public // Run-time
< >
Published // Design-time
< >
End;
:
Private (). . , . , . , .
Protected (). . , , , . , Private.
Public (). . , . Public .
Published (). , Public, Delphi. (RTTI). , Public Published, , Published .
, :
.
, , , ( Real48), , , ( 0..31) ( ).
, ( $+, Public) .
, . .
, Private, - Public.
- Automated, .
. - , "-".
|
|
() - . " -" . , , , -.
(ancestor) - , .
, , (descendant).
, , (parent).
:
, , . , .
, :
, - (, ) , .. TObject. ;
, . - , .
- , , Private, .
, " -" . , " - ", " - ".
:
, -, .
- , - .
- . :
- :
/.<>;
- (typecast):
TParentClass(Obj). <>;
, Private.
4.3.
, , : Static (). Virtual (). Dynamic (), Abstract (). , , . .
) .
. . , . (early binding).
:
, .
, . .
:
TParentClass(Obj). <>;
. , , , .. 1'.
|
|
) .
. . (late binding). , , , . , . , , .
, - , . (Virtual Method Table, VMT). . () : . : , , . , 5 5 , 30 , , 120 (Heap).
VMT - () , .
:
- Virtual, .
Virtual ,
' Obj.StaticMethod, Obj - TClassType, TCIassType.StaticMethod StaticMethod, TCIauType. Obj , TClassType, StaticMethod, .. . TClassType.StaticMethod, .. , . , .. . .
Type T1=Class
Procedure Test; Virtual;
End;
T2=Class(T1)
Procedure Test; // Test ,
End;
Var SomeObject: T1;
Begin
SomeObject:=T2.Create;
SomeObject.Test; // T1. Test
, . , . VMT () , , :
TParentClass(Obj). <>;
:
Procedure|Constructor|Destructor < >[(<>)};
Virtual;
Function < >[(<>)]: < >; Virtual;
|
|
) .
, . - . (Dynamic Method Table, DMT) , . DMT , DMT -, TObject. , DMT DMT .
. , , , . , . :
Proctdure < >[(<>)}; Dynamic;
Function < >[(<>)}: < >;>.1;
.
) .
, Virtual Dynamic , Override . , - , -. Override , , - ( - ) .
Override- Virtual Dynamic , , , . VMT (DMT) , . " , - - VMT (DMT) . "" .
:
Procedure|Constructor|Destructor < >[(<>)]; Override;
Function < >[{<>)]: < >; Override;;
, . , , . ( ) , .
) .
, , . . . , - , . . - Abstract, - Virtual (Dynamic). . , .
:
Procedure < >[(<>)]; Virtual; Abstract;
Function < >[(<>)]: < >;
Virtual; Abstract;
Procedure < >[(<>)]; Dynamic; Abstract;
Function < >[(<>)]: < >;
Dynamic; Abstract;
VMT (DMT) , Nil.
, Override- ().
|
|
, VMT. , , VMT . , VMT ( ), VMT, . .
:
, . Private .
) ( ).
, , . C++ , ( ). , . - Delphi C++ Builder Borland .
, . , .
tqm, , , , - Overload , . , Overload, ( ). , -, .
:
Published ;
- - Reintroduce. Reintroduce:
Procedure < >[(<>)]; Reintroduce; Overload;
Type T1=Class
Procedure Test(I: Integer); Overload; Virtual;
End;
// Overload
T2=Class(T1)
Procedure Test(S: String); Reintroduce; Overload;
End;
Begin
SomeObject:=T2.Create;
SonieObject.Test('HeIlo'); // 2.Test
SomeObject.Test(7); // 1.Test
Tl(SomeObject).Test(7); // , 1
, .
) .
C++ friend , .. , Private . , , , . Delphi.
. Delphi, , .
, . .
:
TObiect - 25 , (17 Delphi 1).
TPersistent - .
TComponent - (Name), (, , ..), (Owner), .
TControl - .
TWinControl - Windows .
TButtonControl - .
TButton - "" : , ..
RTTI
4- , . . . , , , . , .
, 76- (Delphi 5), RTTI (Run-Time Type Information) - , . RTTI Delphi . RTTI - , .1. RTTI , , TObject , : (ClassName), (InstanceSize), - (ClassParent), (ClassType) .. ( -76) VMT, ( -48) DMT.
VMT , . , , . VMT, Inherited.
, , () VMT. DMT , .
, . . RTTI $+. RTTI . Is As, RTTI.
1
-76 | Pointer | vmtSelfPtr | VMT ( Nil) |
-72 | Pointer | vmtIntfTable | ( Nil) |
-68 | Pointer | vmtAutoTable | Automation ( Nil) |
-64 | Pointer | vmtInitTable | ( Nil) |
-60 | Pointer | vmtTypeInfo | ( Nil) |
-56 | Pointer | vmtFieldTable | (Nil) |
-52 | Pointer | vmtMethodTable | ( Nil) |
-48 | Pointer | vmtDynainicTable | DMT ( Nil) |
-44 | Pointer | vmtClassName | |
-40 | Cardinal | vmtInstanceSize | |
-36 | Pointer | vmtParent | ( Nil) |
-32 | Pointer | vmtSafecalIException | SafecallException ( Nil) |
-28 | Pointer | vmtAfterConstruction | AfterConstruction |
-24 | Pointer | vmtBeforeDestruction | BefbreDestruction |
-20 | Pointer | vmtDispatch | Dispatch |
-16 | Pointer | vmtDefaultHandler | DefaultHandler |
-12 | Pointer | vmtNewInstance | Newlnstance |
-8 | Pointer | vmtFreeInstance | Freelnstance |
-4 | Pointer | vmtDestroy | Destroy |
Pointer | vmtQuery Interface | Querylnterface | |
Pointer | vmtAddRef | AddRef | |
Pointer | vmtRelease | Release | |
Pointer | vmtCreateObject | CreateComObject |
Is - . :
If AnObject Is TClassType Then TClassType(AnObject).< >;
<> TClassType , AnObject Is TClassType True. , AnObject TClassType, .. -.
(value typecasting) - - . - , - , .
As . , . , . :