接下来讨论的类类型内部层次结构只适用于Win32平台。
在Win32平台,一个类类型值被存储为32位指针指向类的一个实例,这个实例就叫做对象。一个对象的内部数据格式类似于记录。对象的字段被存储按照声明排列成相邻变量的序列。字段总是对齐的,符合未压缩的记录类型。从父类继承的任何字段被存储在子类定义的新字段之前。
每个对象开始的4字节字段是一个指针指向类的虚拟方法表(VMT)。每个类有一张完整的VMT(不是每个对象)。不同的类类型 ,不管如何相似 ,绝不共享同一VMT。VMT由编译器自动生成,永远不会由程序直接操作。VMT的指针,由自动储存在构造函数生成的对象中,并且永远不会由程序直接操作。
下表描述了一张VMT的结构。在偏移的正数部分,VMT由每个用户在类类型中定义的虚拟方法的32位方法指针列表组成。该结构与C++v-table和com兼容。偏移的负数部分,VMT包含一些字段指向Delphi的内部实现。应用程序应该使用在Tobject中定义的方法来获取这个信息。
Virtual method table layout (Win32 Only)
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
|
Cardinal
|
instance 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
NewInstance method
|
-8
|
Pointer
|
entry point of
FreeInstance 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
|