Fix in invoke to the constructor of the class to return the created instance.

This commit is contained in:
Henrique Gottardi Werlang 2024-02-29 16:19:34 -03:00 committed by Michael Van Canneyt
parent 6940c94333
commit 210ae9b76d

View File

@ -1916,39 +1916,39 @@ end;
function TRttiMethod.Invoke(const Instance: TValue; const Args: array of TValue): TValue; function TRttiMethod.Invoke(const Instance: TValue; const Args: array of TValue): TValue;
var var
A: Integer; A: Integer;
AArgs: TJSValueDynArray; AArgs: TJSValueDynArray;
ReturnValue: JSValue;
begin begin
if Assigned(ReturnType) then
Result.FTypeInfo := ReturnType.Handle;
SetLength(AArgs, Length(Args)); SetLength(AArgs, Length(Args));
for A := Low(Args) to High(Args) do for A := Low(Args) to High(Args) do
AArgs[A] := Args[A].AsJSValue; AArgs[A] := Args[A].AsJSValue;
Result.SetData(TJSFunction(TJSObject(Instance.AsJSValue)[Name]).apply(TJSObject(Instance.AsJSValue), AArgs)); ReturnValue := TJSFunction(TJSObject(Instance.AsJSValue)[Name]).apply(TJSObject(Instance.AsJSValue), AArgs);
if Assigned(ReturnType) then
TValue.Make(ReturnValue, ReturnType.Handle, Result)
else if IsConstructor then
TValue.Make(ReturnValue, Instance.TypeInfo, Result)
end; end;
function TRttiMethod.Invoke(const Instance: TObject; const Args: array of TValue): TValue; function TRttiMethod.Invoke(const Instance: TObject; const Args: array of TValue): TValue;
var var
v : TValue; v: TValue;
begin begin
TValue.make(Instance,Instance.ClassInfo,v); TValue.Make(Instance, Instance.ClassInfo, v);
Result:=Invoke(v,Args); Result := Invoke(v, Args);
end; end;
function TRttiMethod.Invoke(const aClass: TClass; const Args: array of TValue function TRttiMethod.Invoke(const aClass: TClass; const Args: array of TValue): TValue;
): TValue;
var var
v : TValue; v: TValue;
begin begin
TValue.make(aClass,aClass.ClassInfo,v); TValue.Make(aClass, aClass.ClassInfo, v);
Result:=Invoke(V,Args); Result := Invoke(V, Args);
end; end;
{ TRttiProperty } { TRttiProperty }