View Issue Details

IDProjectCategoryView StatusLast Update
0038313pas2jsrtlpublic2021-01-23 11:45
Reporterhenrique Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformPas2JsOSWindows 
Fixed in Versiontrunk 
Summary0038313: Created the implementation for the parameters
DescriptionI created the implementation to load the information about the parameters of the procedures.
TagsNo tags attached.
Fixed in Revision
Attached Files

Activities

henrique

2021-01-05 15:07

reporter  

0001-Carregando-os-par-metros-do-metodo-que-n-o-tinha-sid.patch (3,641 bytes)   
From 6b401dd3f2a20e2d0dbca6e9dcb307850158ff88 Mon Sep 17 00:00:00 2001
From: Henrique Gottardi Werlang <henriquewerlang@hotmail.com>
Date: Tue, 5 Jan 2021 10:54:38 -0300
Subject: [PATCH] =?UTF-8?q?Carregando=20os=20par=C3=A2metros=20do=20metodo?=
 =?UTF-8?q?=20que=20n=C3=A3o=20tinha=20sido=20implementado=20ainda.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 packages/rtl/rtti.pas | 66 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 2 deletions(-)

diff --git a/packages/rtl/rtti.pas b/packages/rtl/rtti.pas
index 9a516a1..c294f72 100644
--- a/packages/rtl/rtti.pas
+++ b/packages/rtl/rtti.pas
@@ -135,12 +135,28 @@ type
     //procedure SetValue(Instance: Pointer; const AValue: TValue);
     //function ToString: string; override;
   end;
-  TRttiFieldArray = array of TRttiField;
+  TRttiFieldArray = specialize TArray<TRttiField>;
+
+  TRttiParameter = class(TRttiNamedObject)
+  private
+    FParamType: TRttiType;
+    FFlags: TParamFlags;
+    FName: String;
+  protected
+    function GetName: string; override;
+  public
+    property Flags: TParamFlags read FFlags;
+    property ParamType: TRttiType read FParamType;
+  end;
+
+  TRttiParameterArray = specialize TArray<TRttiParameter>;
 
   { TRttiMethod }
 
   TRttiMethod = class(TRttiMember)
   private
+    FParameters: TRttiParameterArray;
+
     function GetMethodTypeInfo: TTypeMemberMethod;
     function GetIsClassMethod: boolean;
     function GetIsConstructor: boolean;
@@ -150,7 +166,10 @@ type
     function GetIsVarArgs: boolean;
     function GetMethodKind: TMethodKind;
     function GetReturnType: TRttiType;
+
+    procedure LoadParameters;
   public
+    function GetParameters: TRttiParameterArray;
     property MethodTypeInfo: TTypeMemberMethod read GetMethodTypeInfo;
     property ReturnType: TRttiType read GetReturnType;
     property MethodKind: TMethodKind read GetMethodKind;
@@ -160,7 +179,6 @@ type
     property IsExternal: boolean read GetIsExternal;
     property IsStatic: boolean read GetIsStatic;// true = has Self argument
     property IsVarArgs: boolean read GetIsVarArgs;
-    //function GetParameters:
   end;
 
   TRttiMethodArray = specialize TArray<TRttiMethod>;
@@ -1071,6 +1089,13 @@ begin
   Result := GRttiContext.GetType(FTypeInfo);
 end;
 
+{ TRttiParameter }
+
+function TRttiParameter.GetName: String;
+begin
+  Result := FName;
+end;
+
 { TRttiMethod }
 
 function TRttiMethod.GetMethodTypeInfo: TTypeMemberMethod;
@@ -1118,6 +1143,43 @@ begin
   Result := GRttiContext.GetType(MethodTypeInfo.ProcSig.ResultType);
 end;
 
+procedure TRttiMethod.LoadParameters;
+const
+  FLAGS_CONVERSION: array[TParamFlag] of Integer = (1, 2, 4, 8, 16, 32);
+
+var
+  A, Flag: Integer;
+
+  Param: TProcedureParam;
+
+  RttiParam: TRttiParameter;
+
+begin
+  SetLength(FParameters, Length(MethodTypeInfo.ProcSig.Params));
+
+  for A := Low(FParameters) to High(FParameters) do
+  begin
+    Param := MethodTypeInfo.ProcSig.Params[A];
+    RttiParam := TRttiParameter.Create;
+    RttiParam.FName := Param.Name;
+    RttiParam.FParamType := GRttiContext.GetType(Param.TypeInfo);
+
+    for Flag in FLAGS_CONVERSION do
+      if Flag and Param.Flags > 0 then
+        RttiParam.FFlags := RttiParam.FFlags + [TParamFlag(A)];
+
+    FParameters[A] := RttiParam;
+  end;
+end;
+
+function TRttiMethod.GetParameters: TRttiParameterArray;
+begin
+  if not Assigned(FParameters) then
+    LoadParameters;
+
+  Result := FParameters;
+end;
+
 { TRttiProperty }
 
 constructor TRttiProperty.Create(AParent: TRttiType; ATypeInfo: TTypeMember);
-- 
2.29.2.windows.2

Michael Van Canneyt

2021-01-23 11:45

administrator   ~0128511

Checked and applied, thank you very much !

Issue History

Date Modified Username Field Change
2021-01-05 15:07 henrique New Issue
2021-01-05 15:07 henrique File Added: 0001-Carregando-os-par-metros-do-metodo-que-n-o-tinha-sid.patch
2021-01-05 15:37 Mattias Gaertner Assigned To => Michael Van Canneyt
2021-01-05 15:37 Mattias Gaertner Status new => assigned
2021-01-23 11:45 Michael Van Canneyt Status assigned => resolved
2021-01-23 11:45 Michael Van Canneyt Resolution open => fixed
2021-01-23 11:45 Michael Van Canneyt Fixed in Version => trunk
2021-01-23 11:45 Michael Van Canneyt Note Added: 0128511