Browse Source

* Patch from Henrique Werlang to retrieve declared properties (Bg ID 37598)

michael 5 years ago
parent
commit
1572f8e05f
1 changed files with 37 additions and 2 deletions
  1. 37 2
      packages/rtl/rtti.pas

+ 37 - 2
packages/rtl/rtti.pas

@@ -236,7 +236,8 @@ type
     constructor Create(ATypeInfo: PTypeInfo);
     constructor Create(ATypeInfo: PTypeInfo);
     property ClassTypeInfo: TTypeInfoClass read GetClassTypeInfo;
     property ClassTypeInfo: TTypeInfoClass read GetClassTypeInfo;
     property MetaClassType: TClass read GetMetaClassType;
     property MetaClassType: TClass read GetMetaClassType;
-    //function GetDeclaredProperties: TRttiPropertyArray;
+    function GetProperty(const AName: string): TRttiProperty; override;
+    function GetDeclaredProperties: TRttiPropertyArray; override;
   end;
   end;
 
 
   EInvoke = EJS;
   EInvoke = EJS;
@@ -529,6 +530,36 @@ begin
   inherited Create(ATypeInfo);
   inherited Create(ATypeInfo);
 end;
 end;
 
 
+function TRttiInstanceType.GetProperty(const AName: string): TRttiProperty;
+var
+  A: Integer;
+
+  Info: TTypeInfoClass;
+
+begin
+  Info := TTypeInfoClass(FTypeInfo);
+  Result := nil;
+
+  for A := 0 to Pred(Info.PropCount) do
+    if Info.GetProp(A).Name = AName then
+      Exit(TRttiProperty.Create(Self, Info.GetProp(A)));
+end;
+
+function TRttiInstanceType.GetDeclaredProperties: TRttiPropertyArray;
+var
+  A: Integer;
+
+  Info: TTypeInfoClass;
+
+begin
+  Info := TTypeInfoClass(FTypeInfo);
+
+  SetLength(Result, Info.PropCount);
+
+  for A := 0 to Pred(Info.PropCount) do
+    Result[A] := TRttiProperty.Create(Self, Info.GetProp(A));
+end;
+
 { TRTTIContext }
 { TRTTIContext }
 
 
 class constructor TRTTIContext.Init;
 class constructor TRTTIContext.Init;
@@ -567,7 +598,11 @@ begin
     Result:=TRttiType(FPool[Name])
     Result:=TRttiType(FPool[Name])
   else
   else
     begin
     begin
-    Result:=TRttiType.Create(aTypeInfo);
+      case T.Kind of
+        tkClass: Result:=TRttiInstanceType.Create(aTypeInfo);
+        else Result:=TRttiType.Create(aTypeInfo);
+      end;
+
     FPool[Name]:=Result;
     FPool[Name]:=Result;
     end;
     end;
 end;
 end;