Class Types

A class-type value is stored as a 32-bit pointer to an instance of the class, which is called an object. The internal data format of an object resembles that of a record. The object's fields are stored in order of declaration as a sequence of contiguous variables. Fields are always aligned, corresponding to an unpacked record type. Any fields inherited from an ancestor class are stored before the new fields defined in the descendant class.

The first 4-byte field of every object is a pointer to the virtual method table (VMT) of the class. There is exactly one VMT per class (not one per object); distinct class types, no matter how similar, never share a VMT. VMT's are built automatically by the compiler, and are never directly manipulated by a program. Pointers to VMT's, which are automatically stored by constructor methods in the objects they create, are also never directly manipulated by a program.

The layout of a VMT is shown in the following table. At positive offsets, a VMT consists of a list of 32bit method pointersone per user-defined virtual method in the class typein order of declaration. Each slot contains the address of the corresponding virtual method's entry point. This layout is compatible with a C++ v-table and with COM. At negative offsets, a VMT contains a number of fields that are internal to Delphi's implementation. Applications should use the methods defined in TObject to query this information, since the layout is likely to change in future implementations of the Delphi language.

Virtual method table layout

Offset

Type Description

-76

Pointer pointer to virtual method table (or nil)

-72

Pointer pointer to interface table (or nil)

-68

Pointer pointer to Automation information table (or nil)

-64

Pointer pointer to instance initialization table (or nil)

-60

Pointer pointer to type information table (or nil)

-56

Pointer pointer to field definition table (or nil)

-52

Pointer pointer to method definition table (or nil)

-48

Pointer pointer to dynamic method table (or nil)

-44

Pointer pointer to short string containing class name

-40

Cardinalinstance size in bytes

-36

Pointer pointer to a pointer to ancestor class (or nil)

-32 Pointer pointer to entry point of SafecallException method (or nil)

-28

Pointer entry point of AfterConstruction method

-24

Pointer entry point of BeforeDestruction method

-20

Pointer entry point of Dispatch method

-16

Pointer entry point of DefaultHandler method

-12

Pointer entry point of Newlnstance method

-8 Pointer entry point of Freelnstance method

-4

Pointer entry point of Destroy destructor

0

Pointer entry point of first user-defined virtual method

4

Pointer entry point of second user-defined virtual method

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment