Browse Source

* ensure that TObject.FieldAddress returns the same values as accessing the RTTI directly

Sven/Sarah Barth 1 year ago
parent
commit
bb5b9acbb2
1 changed files with 15 additions and 6 deletions
  1. 15 6
      tests/test/trtti25.pp

+ 15 - 6
tests/test/trtti25.pp

@@ -27,7 +27,10 @@ var
   vft: PVmtFieldTable;
   vft: PVmtFieldTable;
   vfe: PVmtFieldEntry;
   vfe: PVmtFieldEntry;
   vfct: PVmtFieldClassTab;
   vfct: PVmtFieldClassTab;
+  t: TTest;
 begin
 begin
+  t := TTest.Create;
+
   vmt := PVmt(TTest);
   vmt := PVmt(TTest);
   vft := PVmtFieldTable(vmt^.vFieldTable);
   vft := PVmtFieldTable(vmt^.vFieldTable);
   if vft^.Count <> 3 then
   if vft^.Count <> 3 then
@@ -43,20 +46,26 @@ begin
     Halt(4);
     Halt(4);
   if vfct^.ClassRef[vfe^.TypeIndex - 1]^.ClassName <> 'TSub1' then
   if vfct^.ClassRef[vfe^.TypeIndex - 1]^.ClassName <> 'TSub1' then
     Halt(5);
     Halt(5);
+  if t.FieldAddress('Field1') <> PByte(t) + vfe^.FieldOffset then
+    Halt(6);
 
 
   vfe := vft^.Field[1];
   vfe := vft^.Field[1];
   if vfe^.Name <> 'Field2' then
   if vfe^.Name <> 'Field2' then
-    Halt(6);
-  if vfe^.TypeIndex > vfct^.Count then
     Halt(7);
     Halt(7);
-  if vfct^.ClassRef[vfe^.TypeIndex - 1]^.ClassName <> 'TSub2' then
+  if vfe^.TypeIndex > vfct^.Count then
     Halt(8);
     Halt(8);
+  if vfct^.ClassRef[vfe^.TypeIndex - 1]^.ClassName <> 'TSub2' then
+    Halt(9);
+  if t.FieldAddress('Field2') <> PByte(t) + vfe^.FieldOffset then
+    Halt(10);
 
 
   vfe := vft^.Field[2];
   vfe := vft^.Field[2];
   if vfe^.Name <> 'Field3' then
   if vfe^.Name <> 'Field3' then
-    Halt(9);
+    Halt(11);
   if vfe^.TypeIndex > vfct^.Count then
   if vfe^.TypeIndex > vfct^.Count then
-    Halt(10);
+    Halt(12);
   if vfct^.ClassRef[vfe^.TypeIndex - 1]^.ClassName <> 'TSub1' then
   if vfct^.ClassRef[vfe^.TypeIndex - 1]^.ClassName <> 'TSub1' then
-    Halt(11);
+    Halt(13);
+  if t.FieldAddress('Field3') <> PByte(t) + vfe^.FieldOffset then
+    Halt(14);
 end.
 end.