. , , ,

,,,

TObject. — ,

Delphi TObject, , , . , , , , ? , TObject Delphi.

.

 

TObject = class

constructor Create;

procedure Free;

class function InitInstance(Instance: Pointer): TObject;

procedure CleanupInstance;

function ClassType: TClass;

class function ClassName: ShortString;

class function ClassNameIs(const Name: string): Boolean;

class function ClassParent: TClass;

class function ClassInfo: Pointer;

class function InstanceSize: Longint;

class function InheritsFrom(AClass: TClass): Boolean;

class function MethodAddress(const Name: ShortString): Pointer;

class function MethodName(Address: Pointer): ShortString;

function FieldAddress(const Name: ShortString): Pointer;

function GetInterface(const IID: TGUID; out Obj): Boolean;

class function GetInterfaceEntry(const IID: TGUID): PInterfaceEntry;

class function GetInterfaceTable: PInterfaceTable;

function SafeCallException(ExceptObject: TObject;

ExceptAddr: Pointer): HResult; virtual;

 

procedure AfterConstruction; virtual;

procedure BeforeDestruction; virtual;

procedure Dispatch(var Message); virtual;

 

procedure DefaultHandler(var Message); virtual;

class function NewInstance: TObject; virtual;

procedure FreeInstance; virtual;

destructor Destroy; virtual;

end;

, , , . .

, - , , , .

Constructor Create;

. Create, . , :

NewInstance

InitInstance

Create

AfterConstruction

. TObject , , RTM. ? RTM NewInstance, , vmtInstanceSize, . NewInstance InitInstance, , default, , Create ( , ), , vmtAfterConstruction, AfterConstruction. Delphi. , () . AfterConstruction , . , , , . TCustomForm TCustomDataModule , , ? .

? , , . , - , .

, , , :

 

Var

O : TObject;

Begin

O.Create; //

O := TObject.Create; //

End;

, -, , , .

Procedure Free;

. ? object. , , .

 

procedure TObject.Free;

asm

TEST EAX,EAX

JE @@exit

MOV ECX,[EAX]

MOV DL,1

CALL dword ptr [ECX].vmtDestroy

@@exit:

end;

? Self () - ? , vmtDestroy . . RTM Delphi. ( , ) . .

BeforeDestruction

FreeInstance

FreeInstance , , , Variant . . .

class function InitInstance(Instance: Pointer): TObject;

VMT, . , , , NewInstance.

Procedure CleanupInstance;

. , vmtInitTable vmtParent.

Function ClassType: TClass;

. , VMT.

class function ClassName: ShortString;

. VMT.

class function ClassNameIs(const Name: string): Boolean;

. is.

class function ClassParent: TClass;

. is.

class function ClassInfo: Pointer;

RTTI . $M+, nil.

class function InstanceSize: Longint;

. RTTI VMT . , .

class function InheritsFrom(AClass: TClass): Boolean;

, . VMT VMT .

class function MethodAddress(const Name: ShortString): Pointer;

VMT . "" VMT VMT , ( ) . Delphi.

class function MethodName(Address: Pointer): ShortString;

.

Function FieldAddress(const Name: ShortString): Pointer;

. . VMT.

Function GetInterface(const IID: TGUID; out Obj): Boolean;

IID.

class function GetInterfaceEntry(const IID: TGUID): PinterfaceEntry;

IID.

class function GetInterfaceTable: PInterfaceTable;

. , , 10000 . , , , , , , .

Function SafeCallException(ExceptObject: TObject; ExceptAddr: Pointer): HResult; virtual;

, , TObject E_UNEXPECTED, - . , .

Procedure AfterConstruction; virtual;

, . , VMT. , , RTM, .

Procedure BeforeDestruction; virtual;

, .

Procedure Dispatch(var Message); virtual;

Windows - . . TObject, , Delphi. VMT , ID 4 ( ,Cardinal) Message , DefaultHandler. , , .

Procedure DefaultHandler(var Message); virtual;

. Dispatch - .

class function NewInstance: TObject; virtual;

. , , , RTTI.

procedure FreeInstance; virtual;

. VMT, . InitInstance , , .

destructor Destroy; virtual;

. Free , . - Destroy, , . , RTM , . . , - , , , , .

TObject, Delphi, , . VMT, RTTI . RTTI, , , RunTime .

- EAX VMT! Delphi?! "Delphi in nutshell" (Ray Lischner) - , :

.

Delphi C++ Java Visual Basic
+ + +
+
+ + +
+ +
+ +
+ +
+ + +
+ + +
+ + +
+
+
Variant + +
OLE automation + +
+ + +
+ + + +
+ + +
+ +
+
- + + +
- + + +
+ +
RTTI +

is as

+
() +
+ +
+
+ +

Inline

+
+ +
+

, . ? - , - , . ?

( Java - final, ) , , Create TObject - , . , , .

, VMT. :

DoOne Self.DoOne
DoTwo Self.Parent.DoTwo
DoThree Self.Parent.Parent.DoThree

, , , . , , - . , , .

, . , , , .

, . - reintroduce , .

TObject - VMT : QueryInterface, AddRef Release. , Delphi COM ! , , TInterfacedObject.

! . , .

http://coderpro.fatal.ru/

Delphi TObject, , , . , , , ,

 

 

 

! , , , .
. , :