RTTI

{ Virtual method table entries }

vmtSelfPtr           = -88;

vmtIntfTable         = -84;

vmtAutoTable         = -80;

vmtInitTable         = -76;

vmtTypeInfo          = -72;

vmtFieldTable        = -68;

vmtMethodTable       = -64;

vmtDynamicTable      = -60;

vmtClassName         = -56;

vmtInstanceSize      = -52;

vmtParent            = -48;

vmtEquals            = -44 deprecated 'Use VMTOFFSET in asm code';

vmtGetHashCode       = -40 deprecated 'Use VMTOFFSET in asm code';

vmtToString          = -36 deprecated 'Use VMTOFFSET in asm code';

vmtSafeCallException = -32 deprecated 'Use VMTOFFSET in asm code';

vmtAfterConstruction = -28 deprecated 'Use VMTOFFSET in asm code';

vmtBeforeDestruction = -24 deprecated 'Use VMTOFFSET in asm code';

vmtDispatch          = -20 deprecated 'Use VMTOFFSET in asm code';

vmtDefaultHandler    = -16 deprecated 'Use VMTOFFSET in asm code';

vmtNewInstance       = -12 deprecated 'Use VMTOFFSET in asm code';

vmtFreeInstance      = -8 deprecated 'Use VMTOFFSET in asm code';

vmtDestroy           = -4 deprecated 'Use VMTOFFSET in asm code';

vmtQueryInterface    = 0 deprecated 'Use VMTOFFSET in asm code';

vmtAddRef            = 4 deprecated 'Use VMTOFFSET in asm code';

vmtRelease           = 8 deprecated 'Use VMTOFFSET in asm code';

vmtCreateObject      = 12 deprecated 'Use VMTOFFSET in asm code';

Delphi运行期间,一个对象变量实际上是一个四字节指针,指向内存中此对象具体占据的一片区域,而区域的首个四字节又是一个指针指向该类的VMT,所有该类的实例对象的区域的首四字节指针都指向同一个VMT,故此一个VMT基本上就可以代表类本身。而每个类的VMT前面(VMT指针所指处的负偏移处)保存了该类的一些运行期信息,包括-44(vmtClassName)处的指向ClassName的字符串指针,-40(vmtInstanceSize)处的对象实例大小InstanceSize等。而本文专门讲述其-60(vmtTypeInfo)处的TypeInfo/ClassInfo指针所指的、本类的属性的RTTI信息。

posted @ 2012-08-29 17:03  realnull  阅读(282)  评论(0编辑  收藏  举报