From 414ef0fe37af3827151d231ac169ddbc79410add Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 2 Mar 2021 13:19:52 +0000 Subject: [PATCH] * Patch from henrique werlang to allow get/set value of records (Issue ID 38569) --- packages/rtl/rtti.pas | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 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: 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(JSObject, PropertyTypeInfo, AValue); end; procedure TRttiProperty.SetValue(Instance: TObject; const AValue: TValue); begin - SetJSValueProp(Instance, PropertyTypeInfo, AValue.AsJSValue); -end; - -procedure TRttiProperty.SetValue(Instance: TObject; const AValue: JSValue); -begin - SetJSValueProp(Instance, PropertyTypeInfo, AValue); + SetValue(JSValue(Instance), AValue); end; function TRttiProperty.GetPropertyType: TRttiType; - begin Result := GRttiContext.GetType(PropertyTypeInfo.TypeInfo); end;