Don't fully understand what is happening, but when you look at IsPublishedProp in TypInfo , you will see that it defines the ClassInfo of the instance as a pointer to the TypeInfo structure:
PTypeInfo(Instance.ClassInfo)
When you look at the ClassInfo method, it returns a simple pointer whose value is similar to the vmt table:
Result := PPointer(Integer(Self) + vmtTypeInfo)^;
vmtTypeInfo has a value of -72. Four bytes before that at -76 is equal to vmtInitTable . VmtTypeInfo is followed by FieldTable, MethodTable, DynamicTable, etc.
The value vmtInitTable is used, for example, in TObject.CleanupInstance and passed to _FinalizeRecord as a pointer to the TypeInfo structure.
Thus, the four bytes in front of the TypeInfo structure, pointing to the TypeInfo structure, seem to exist by design and part of the vmt structure.
Edit
As Mason rightly pointed out, this is a complete red herring (see comments). I leave the answer so that others do not have to chase him.
Update To avoid confusion over the variables and their addresses, I rewrote the Mason testing procedure as follows:
procedure test(info: PTypeInfo); begin writeln('value of info : ', cardinal(info)); writeln('info - 4 : ', cardinal(info) - 4); writeln('value 4 bytes before: ', cardinal(PPointer(cardinal(info)-4)^)); end;
and call it the following information:
procedure TryRTTIStuff; begin writeln('TPersistent'); test(TypeInfo(TPersistent)); writeln('TTypeKind enumeration'); test(TypeInfo(TTypeKind)); writeln('Integer'); test(TypeInfo(Integer)); writeln('Nonsense'); test(PTypeInfo($420000)); end;
The first three give the results that Mason describes. I added only an additional file to show the pointer value for the last writeln file. The last call to TryRTTIStuff should show that when you do not pass a pointer to a valid TypeInfo structure, you will not get the same value in the first and third scripts for the call.
There is no clue as to what is happening with TypeInfo. Maybe we should ask Barry Kelly, as he is the author of the new D2010 RTTI, so he should know a lot about the old, as well ...