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 years ago
parent
commit
c6233697be
1 changed files with 33 additions and 1 deletions
  1. 33 1
      rtl/objpas/typinfo.pp

+ 33 - 1
rtl/objpas/typinfo.pp

@@ -446,18 +446,25 @@ unit typinfo;
               (RefTypeRef: TypeInfoPtr);
               (RefTypeRef: TypeInfoPtr);
       end;
       end;
 
 
+      PPropInfo = ^TPropInfo;
+
       PPropData = ^TPropData;
       PPropData = ^TPropData;
       TPropData =
       TPropData =
 {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
 {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
       packed
       packed
 {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
 {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
       record
       record
+      private
+        function GetProp(Index: Word): PPropInfo;
+        function GetTail: Pointer; inline;
+      public
         PropCount : Word;
         PropCount : Word;
         PropList : record _alignmentdummy : ptrint; end;
         PropList : record _alignmentdummy : ptrint; end;
+        property Prop[Index: Word]: PPropInfo read GetProp;
+        property Tail: Pointer read GetTail;
       end;
       end;
 
 
 {$PACKRECORDS 1}
 {$PACKRECORDS 1}
-      PPropInfo = ^TPropInfo;
       TPropInfo = packed record
       TPropInfo = packed record
       private
       private
         function GetPropType: PTypeInfo; inline;
         function GetPropType: PTypeInfo; inline;
@@ -2526,6 +2533,31 @@ begin
   Result := DerefTypeInfoPtr(RefTypeRef);
   Result := DerefTypeInfoPtr(RefTypeRef);
 end;
 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 }
 { TPropInfo }
 
 
 function TPropInfo.GetPropType: PTypeInfo;
 function TPropInfo.GetPropType: PTypeInfo;