View Issue Details

IDProjectCategoryView StatusLast Update
0038569pas2jsrtlpublic2021-03-02 14:20
Reporterhenrique Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformPas2JsOSWindows 
Fixed in Versiontrunk 
Summary0038569: Get and Set value to records
DescriptionI modified the implementation in RTTI of the GetValue and SetValue to work with record types.
TagsNo tags attached.
Fixed in Revision1092
Attached Files

Activities

henrique

2021-03-02 13:22

reporter  

0001-Modificado-o-forma-que-pega-os-valores-das-proprieda.patch (3,654 bytes)   
From 65b91ef8ce6096932d9b49e195a895cde09451e5 Mon Sep 17 00:00:00 2001
From: Henrique Gottardi Werlang <henriquewerlang@hotmail.com>
Date: Tue, 2 Mar 2021 09:12:16 -0300
Subject: [PATCH] Modificado o forma que pega os valores das propriedades para
 funcionar com os records.

---
 packages/rtl/rtti.pas | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/packages/rtl/rtti.pas b/packages/rtl/rtti.pas
index ea9e83c..219b626 100644
--- a/packages/rtl/rtti.pas
+++ b/packages/rtl/rtti.pas
@@ -138,8 +138,8 @@ type
     function GetFieldTypeInfo: TTypeMemberField;
   public
     constructor Create(AParent: TRttiType; ATypeInfo: TTypeMember);
-    function GetValue(Instance: TObject): TValue;
-    procedure SetValue(Instance: TObject; const AValue: TValue);
+    function GetValue(Instance: JSValue): TValue;
+    procedure SetValue(Instance: JSValue; const AValue: TValue);
     property FieldType: TRttiType read GetFieldType;
     property FieldTypeInfo: TTypeMemberField read GetFieldTypeInfo;
   end;
@@ -204,9 +204,10 @@ type
     function GetVisibility: TMemberVisibility; override;
   public
     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;
 
     property PropertyTypeInfo: TTypeMemberProperty read GetPropertyTypeInfo;
@@ -1293,7 +1294,7 @@ begin
   Result := TTypeMemberField(FTypeInfo);
 end;
 
-function TRttiField.GetValue(Instance: TObject): TValue;
+function TRttiField.GetValue(Instance: JSValue): TValue;
 var
   JSInstance: TJSObject absolute Instance;
 
@@ -1301,7 +1302,7 @@ begin
   Result := TValue.FromJSValue(JSInstance[Name]);
 end;
 
-procedure TRttiField.SetValue(Instance: TObject; const AValue: TValue);
+procedure TRttiField.SetValue(Instance: JSValue; const AValue: TValue);
 var
   JSInstance: TJSObject absolute Instance;
 
@@ -1415,23 +1416,36 @@ begin
   Result := TTypeMemberProperty(FTypeInfo);
 end;
 
-function TRttiProperty.GetValue(Instance: TObject): TValue;
+function TRttiProperty.GetValue(Instance: JSValue): TValue;
+var
+  JSObject: TJSObject absolute Instance;
+
 begin
-  Result := TValue.Make(PropertyType.Handle, GetJSValueProp(Instance, PropertyTypeInfo));
+  Result := TValue.Make(PropertyType.Handle, GetJSValueProp(JSObject, PropertyTypeInfo));
 end;
 
-procedure TRttiProperty.SetValue(Instance: TObject; const AValue: TValue);
+procedure TRttiProperty.SetValue(Instance: JSValue; const AValue: TValue);
+var
+  JSObject: TJSObject absolute Instance;
+
+begin
+  SetJSValueProp(JSObject, PropertyTypeInfo, AValue.AsJSValue);
+end;
+
+procedure TRttiProperty.SetValue(Instance: JSValue; const AValue: JSValue);
+var
+  JSObject: TJSObject absolute Instance;
+
 begin
-  SetJSValueProp(Instance, PropertyTypeInfo, AValue.AsJSValue);
+  SetJSValueProp(JSObject, PropertyTypeInfo, AValue);
 end;
 
-procedure TRttiProperty.SetValue(Instance: TObject; const AValue: JSValue);
+procedure TRttiProperty.SetValue(Instance: TObject; const AValue: TValue);
 begin
-  SetJSValueProp(Instance, PropertyTypeInfo, AValue);
+  SetValue(JSValue(Instance), AValue);
 end;
 
 function TRttiProperty.GetPropertyType: TRttiType;
-
 begin
   Result := GRttiContext.GetType(PropertyTypeInfo.TypeInfo);
 end;
-- 
2.30.0.windows.1

Michael Van Canneyt

2021-03-02 13:36

administrator   ~0129313

Patch does not apply (3/5 hunks fail), can you please create a new one ?

henrique

2021-03-02 14:00

reporter   ~0129317

Yes, just a minute.

henrique

2021-03-02 14:12

reporter   ~0129318

New patch.
0001-Modificado-a-implementa-o-do-Get-e-Set-value-das-pro.patch (2,954 bytes)   
From ecd5a7bd4c90e0f08a0c3e033cf95740aae56139 Mon Sep 17 00:00:00 2001
From: Henrique Gottardi Werlang <henriquewerlang@hotmail.com>
Date: Tue, 2 Mar 2021 10:08:55 -0300
Subject: [PATCH] =?UTF-8?q?Modificado=20a=20implementa=C3=A7=C3=A3o=20do?=
 =?UTF-8?q?=20Get=20e=20Set=20value=20das=20propriedades.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 packages/rtl/rtti.pas | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/packages/rtl/rtti.pas b/packages/rtl/rtti.pas
index 4f6f389..6f8088c 100644
--- a/packages/rtl/rtti.pas
+++ b/packages/rtl/rtti.pas
@@ -201,9 +201,10 @@ type
     function GetVisibility: TMemberVisibility; override;
   public
     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;
 
     property PropertyTypeInfo: TTypeMemberProperty read GetPropertyTypeInfo;
@@ -377,7 +378,6 @@ type
     property ElementType: TRttiType read GetElementType;
   end;
 
-
   EInvoke = EJS;
 
   TVirtualInterfaceInvokeEvent = function(const aMethodName: string;
@@ -1295,23 +1295,36 @@ begin
   Result := TTypeMemberProperty(FTypeInfo);
 end;
 
-function TRttiProperty.GetValue(Instance: TObject): TValue;
+function TRttiProperty.GetValue(Instance: JSValue): TValue;
+var
+  JSObject: TJSObject absolute Instance;
+
 begin
-  Result := TValue.Make(PropertyType.Handle, GetJSValueProp(Instance, PropertyTypeInfo));
+  Result := TValue.Make(PropertyType.Handle, GetJSValueProp(JSObject, PropertyTypeInfo));
 end;
 
-procedure TRttiProperty.SetValue(Instance: TObject; const AValue: TValue);
+procedure TRttiProperty.SetValue(Instance: JSValue; const AValue: TValue);
+var
+  JSObject: TJSObject absolute Instance;
+
 begin
-  SetJSValueProp(Instance, PropertyTypeInfo, AValue.AsJSValue);
+  SetJSValueProp(JSObject, PropertyTypeInfo, AValue.AsJSValue);
 end;
 
-procedure TRttiProperty.SetValue(Instance: TObject; const AValue: JSValue);
+procedure TRttiProperty.SetValue(Instance: JSValue; const AValue: JSValue);
+var
+  JSObject: TJSObject absolute Instance;
+
 begin
-  SetJSValueProp(Instance, PropertyTypeInfo, AValue);
+  SetJSValueProp(JSObject, PropertyTypeInfo, AValue);
 end;
 
-function TRttiProperty.GetPropertyType: TRttiType;
+procedure TRttiProperty.SetValue(Instance: TObject; const AValue: TValue);
+begin
+  SetValue(JSValue(Instance), AValue);
+end;
 
+function TRttiProperty.GetPropertyType: TRttiType;
 begin
   Result := GRttiContext.GetType(PropertyTypeInfo.TypeInfo);
 end;
-- 
2.30.0.windows.1

Michael Van Canneyt

2021-03-02 14:20

administrator   ~0129319

Applied, thank you very much !

Issue History

Date Modified Username Field Change
2021-03-02 13:22 henrique New Issue
2021-03-02 13:22 henrique File Added: 0001-Modificado-o-forma-que-pega-os-valores-das-proprieda.patch
2021-03-02 13:36 Michael Van Canneyt Note Added: 0129313
2021-03-02 13:36 Michael Van Canneyt Assigned To => Michael Van Canneyt
2021-03-02 13:36 Michael Van Canneyt Status new => assigned
2021-03-02 14:00 henrique Note Added: 0129317
2021-03-02 14:12 henrique Note Added: 0129318
2021-03-02 14:12 henrique File Added: 0001-Modificado-a-implementa-o-do-Get-e-Set-value-das-pro.patch
2021-03-02 14:20 Michael Van Canneyt Status assigned => resolved
2021-03-02 14:20 Michael Van Canneyt Resolution open => fixed
2021-03-02 14:20 Michael Van Canneyt Fixed in Version => trunk
2021-03-02 14:20 Michael Van Canneyt Fixed in Revision => 1092
2021-03-02 14:20 Michael Van Canneyt Note Added: 0129319