Browse Source

Fix for invoking the constructor of the class using the RTTI.

Henrique Gottardi Werlang 1 year ago
parent
commit
bc9da80549
1 changed files with 11 additions and 1 deletions
  1. 11 1
      packages/rtl/src/rtti.pas

+ 11 - 1
packages/rtl/src/rtti.pas

@@ -221,6 +221,8 @@ type
     function GetReturnType: TRttiType;
     function GetReturnType: TRttiType;
 
 
     procedure LoadParameters;
     procedure LoadParameters;
+  protected
+    function GetName: String; override;
   public
   public
     function GetParameters: TRttiParameterArray;
     function GetParameters: TRttiParameterArray;
     function Invoke(const Instance: TValue; const Args: array of TValue): TValue;
     function Invoke(const Instance: TValue; const Args: array of TValue): TValue;
@@ -1881,6 +1883,14 @@ begin
   Result := Pool.GetType(MethodTypeInfo.ProcSig.ResultType);
   Result := Pool.GetType(MethodTypeInfo.ProcSig.ResultType);
 end;
 end;
 
 
+function TRttiMethod.GetName: String;
+begin
+  Result := inherited;
+
+  if IsConstructor then
+    Result := Result.SubString(0, Result.IndexOf('$'));
+end;
+
 procedure TRttiMethod.LoadParameters;
 procedure TRttiMethod.LoadParameters;
 const
 const
   FLAGS_CONVERSION: array[TParamFlag] of NativeInt = (1, 2, 4, 8, 16, 32);
   FLAGS_CONVERSION: array[TParamFlag] of NativeInt = (1, 2, 4, 8, 16, 32);
@@ -1937,7 +1947,7 @@ begin
   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;
 
 
-  ReturnValue := TJSFunction(TJSObject(Instance.AsJSValue)[Name]).apply(TJSObject(Instance.AsJSValue), AArgs);
+  ReturnValue := TJSFunction(TJSObject(Instance.AsJSValue)[MethodTypeInfo.Name]).apply(TJSObject(Instance.AsJSValue), AArgs);
 
 
   if Assigned(ReturnType) then
   if Assigned(ReturnType) then
     TValue.Make(ReturnValue, ReturnType.Handle, Result)
     TValue.Make(ReturnValue, ReturnType.Handle, Result)