Browse Source

* Get/Set value for objects, patch by Henrique Werlang (Bug ID 37540)

michael 5 years ago
parent
commit
8a7ce44e4f
1 changed files with 13 additions and 2 deletions
  1. 13 2
      packages/rtl/rtti.pas

+ 13 - 2
packages/rtl/rtti.pas

@@ -166,8 +166,8 @@ type
   protected
   protected
     function GetVisibility: TMemberVisibility; override;
     function GetVisibility: TMemberVisibility; override;
   public
   public
-    //function GetValue(Instance: Pointer): TValue;
-    //procedure SetValue(Instance: Pointer; const AValue: TValue);
+    function GetValue(Instance: TObject): TValue;
+    procedure SetValue(Instance: TObject; const AValue: TValue);
     property PropertyType: TRttiType read GetPropertyType;
     property PropertyType: TRttiType read GetPropertyType;
     property IsReadable: boolean read GetIsReadable;
     property IsReadable: boolean read GetIsReadable;
     property IsWritable: boolean read GetIsWritable;
     property IsWritable: boolean read GetIsWritable;
@@ -209,6 +209,7 @@ type
     function GetDeclaredMethods: TRttiMethodArray; virtual;
     function GetDeclaredMethods: TRttiMethodArray; virtual;
     function GetDeclaredFields: TRttiFieldArray; virtual;
     function GetDeclaredFields: TRttiFieldArray; virtual;
 
 
+    property Handle: TTypeInfo read FTypeInfo;
     property IsInstance: boolean read GetIsInstance;
     property IsInstance: boolean read GetIsInstance;
     //property isManaged: boolean read GetIsManaged;
     //property isManaged: boolean read GetIsManaged;
     property IsOrdinal: boolean read GetIsOrdinal;
     property IsOrdinal: boolean read GetIsOrdinal;
@@ -666,6 +667,16 @@ end;
 
 
 { TRttiProperty }
 { TRttiProperty }
 
 
+function TRttiProperty.GetValue(Instance: TObject): TValue;
+begin
+  Result := TValue.FromJSValue(GetJSValueProp(Instance, TTypeMemberProperty(FTypeInfo)));
+end;
+
+procedure TRttiProperty.SetValue(Instance: TObject; const AValue: TValue);
+begin
+  SetJSValueProp(Instance, TTypeMemberProperty(FTypeInfo), AValue);
+end;
+
 function TRttiProperty.GetPropertyType: TRttiType;
 function TRttiProperty.GetPropertyType: TRttiType;
 begin
 begin
   Result := GRttiContext.GetType(FTypeInfo);
   Result := GRttiContext.GetType(FTypeInfo);