Browse Source

* Patch from henrique werlang to allow get/set value of records (Issue ID 38569)

michael 4 years ago
parent
commit
414ef0fe37
1 changed files with 23 additions and 10 deletions
  1. 23 10
      packages/rtl/rtti.pas

+ 23 - 10
packages/rtl/rtti.pas

@@ -201,9 +201,10 @@ type
     function GetVisibility: TMemberVisibility; override;
     function GetVisibility: TMemberVisibility; override;
   public
   public
     constructor Create(AParent: TRttiType; ATypeInfo: TTypeMember);
     constructor Create(AParent: TRttiType; ATypeInfo: TTypeMember);
-    function GetValue(Instance: TObject): TValue;
+    function GetValue(Instance: JSValue): TValue;
 
 
-    procedure SetValue(Instance: TObject; const AValue: JSValue); overload;
+    procedure SetValue(Instance: JSValue; const AValue: JSValue); overload;
+    procedure SetValue(Instance: JSValue; const AValue: TValue); overload;
     procedure SetValue(Instance: TObject; const AValue: TValue); overload;
     procedure SetValue(Instance: TObject; const AValue: TValue); overload;
 
 
     property PropertyTypeInfo: TTypeMemberProperty read GetPropertyTypeInfo;
     property PropertyTypeInfo: TTypeMemberProperty read GetPropertyTypeInfo;
@@ -377,7 +378,6 @@ type
     property ElementType: TRttiType read GetElementType;
     property ElementType: TRttiType read GetElementType;
   end;
   end;
 
 
-
   EInvoke = EJS;
   EInvoke = EJS;
 
 
   TVirtualInterfaceInvokeEvent = function(const aMethodName: string;
   TVirtualInterfaceInvokeEvent = function(const aMethodName: string;
@@ -1295,23 +1295,36 @@ begin
   Result := TTypeMemberProperty(FTypeInfo);
   Result := TTypeMemberProperty(FTypeInfo);
 end;
 end;
 
 
-function TRttiProperty.GetValue(Instance: TObject): TValue;
+function TRttiProperty.GetValue(Instance: JSValue): TValue;
+var
+  JSObject: TJSObject absolute Instance;
+
 begin
 begin
-  Result := TValue.Make(PropertyType.Handle, GetJSValueProp(Instance, PropertyTypeInfo));
+  Result := TValue.Make(PropertyType.Handle, GetJSValueProp(JSObject, PropertyTypeInfo));
 end;
 end;
 
 
-procedure TRttiProperty.SetValue(Instance: TObject; const AValue: TValue);
+procedure TRttiProperty.SetValue(Instance: JSValue; const AValue: TValue);
+var
+  JSObject: TJSObject absolute Instance;
+
 begin
 begin
-  SetJSValueProp(Instance, PropertyTypeInfo, AValue.AsJSValue);
+  SetJSValueProp(JSObject, PropertyTypeInfo, AValue.AsJSValue);
 end;
 end;
 
 
-procedure TRttiProperty.SetValue(Instance: TObject; const AValue: JSValue);
+procedure TRttiProperty.SetValue(Instance: JSValue; const AValue: JSValue);
+var
+  JSObject: TJSObject absolute Instance;
+
 begin
 begin
-  SetJSValueProp(Instance, PropertyTypeInfo, AValue);
+  SetJSValueProp(JSObject, PropertyTypeInfo, AValue);
 end;
 end;
 
 
-function TRttiProperty.GetPropertyType: TRttiType;
+procedure TRttiProperty.SetValue(Instance: TObject; const AValue: TValue);
+begin
+  SetValue(JSValue(Instance), AValue);
+end;
 
 
+function TRttiProperty.GetPropertyType: TRttiType;
 begin
 begin
   Result := GRttiContext.GetType(PropertyTypeInfo.TypeInfo);
   Result := GRttiContext.GetType(PropertyTypeInfo.TypeInfo);
 end;
 end;