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

This commit is contained in:
michael 2021-03-02 13:19:52 +00:00
parent 4cbd08c400
commit 414ef0fe37

View File

@ -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;