Browse Source

+ add utility properties to TPropData to access a specific TPropInfo or the end of the known data of all properties

git-svn-id: trunk@35338 -
svenbarth 8 năm trước cách đây
mục cha
commit
c6233697be
1 tập tin đã thay đổi với 33 bổ sung1 xóa
  1. 33 1
      rtl/objpas/typinfo.pp

+ 33 - 1
rtl/objpas/typinfo.pp

@@ -446,18 +446,25 @@ unit typinfo;
               (RefTypeRef: TypeInfoPtr);
       end;
 
+      PPropInfo = ^TPropInfo;
+
       PPropData = ^TPropData;
       TPropData =
 {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
       packed
 {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
       record
+      private
+        function GetProp(Index: Word): PPropInfo;
+        function GetTail: Pointer; inline;
+      public
         PropCount : Word;
         PropList : record _alignmentdummy : ptrint; end;
+        property Prop[Index: Word]: PPropInfo read GetProp;
+        property Tail: Pointer read GetTail;
       end;
 
 {$PACKRECORDS 1}
-      PPropInfo = ^TPropInfo;
       TPropInfo = packed record
       private
         function GetPropType: PTypeInfo; inline;
@@ -2526,6 +2533,31 @@ begin
   Result := DerefTypeInfoPtr(RefTypeRef);
 end;
 
+{ TPropData }
+
+function TPropData.GetProp(Index: Word): PPropInfo;
+begin
+  if Index >= PropCount then
+    Result := Nil
+  else
+    begin
+      Result := PPropInfo(aligntoptr(PByte(@PropCount) + SizeOf(PropCount)));
+      while Index > 0 do
+        begin
+          Result := aligntoptr(Result^.Tail);
+          Dec(Index);
+        end;
+    end;
+end;
+
+function TPropData.GetTail: Pointer;
+begin
+  if PropCount = 0 then
+    Result := PByte(@PropCount) + SizeOf(PropCount)
+  else
+    Result := Prop[PropCount - 1]^.Tail;
+end;
+
 { TPropInfo }
 
 function TPropInfo.GetPropType: PTypeInfo;