. . . .
.
Delphi , private, protected, public published, .
Private (). , . private .
Protected (). , protected, , . , .
Public (). . public.
Published (). , , (RTTI Runtime Type Information). , published. B , Object Inspector .
.
Delphi TObject, , , . TObject System, .
.
Type
TFoo = class
...
end;
Type
TFoo = class (TObject)
...
end;
TObject (, ). constructor Create, destructor Destroy. , TObject Free, , , Destroy.
, () (). Delphi . (, , ) ( , ), . , , .
|
|
, TPoint, TInfo:
Type
TPoint = class (TInfo)
x, y: Integer;
constructor Create(ax, ay: Integer);
procedure Show;
end;
TPoint FKey Show, GetKey TInfo. Show TPoint , .. -. , ( ):
...
Var
P: TPoint;
K: TInfo;
Begin
P: = TPoint.Create(200, 305);
K: = TInfo.Create;
K.SetKey(2);
P.Show; // Show TPoint
K.Show; // Show TInfo
...
, , .. .
(static), (virtual), (dynamic) (message).
:
Type
TMyObject = class (TObject)
procedure IAmAStatic;
procedure IAmAVirtual; virtual;
procedure IAmADynamic; dynamic;
end;
IAmAStatic . . , . , .
IAmAVirtual . - , , . (VMT Virtual Method Table), . VMT , , , .
IAmADynamic , -. (DMT Dynamic Method Table). VMT, DMT , , , , DMT .
(overriding) Delphi . . , virtual dynamic. virtual dynamic override. IAmAVirtual IAmADynamic.
|
|
Type
TMyObjectChild - class (TMyObject)
procedure IAmAVirtual; override;
procedure IAmADynamic; override;
end;
override VMT , DMT . virtual dynamic, override, , . , . , , .
, , , . overload
Type
TSampleClass = class
procedure AMethod(I: Integer); overload;
procedure AMethod(S: string); overload;
procedure AMethod(D: Double); overload;
end;