Skip to content

Commit d7560ca

Browse files
committed
[rttiUtils] new function callmethod
1 parent 242d1a3 commit d7560ca

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Quick.RTTI.Utils.pas

+22-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Author : Kike Pérez
88
Version : 1.4
99
Created : 09/03/2018
10-
Modified : 03/04/2020
10+
Modified : 14/07/2020
1111
1212
This file is part of QuickLib: https://github.com/exilon/QuickLib
1313
@@ -76,6 +76,7 @@ TRTTI = class
7676
class function FindClass(const aClassName: string): TClass;
7777
class function CreateInstance<T>: T; overload;
7878
class function CreateInstance(aBaseClass : TClass): TObject; overload;
79+
class function CallMethod(aObject : TObject; const aMethodName : string; aParams : array of TValue) : TValue;
7980
{$ENDIF}
8081
end;
8182

@@ -123,6 +124,7 @@ class function TRTTI.CreateInstance(aBaseClass : TClass): TObject;
123124
rmethod: TRttiMethod;
124125
rinstype: TRttiInstanceType;
125126
begin
127+
Result := nil;
126128
rtype := fCtx.GetType(aBaseClass);
127129
for rmethod in rtype.GetMethods do
128130
begin
@@ -136,6 +138,25 @@ class function TRTTI.CreateInstance(aBaseClass : TClass): TObject;
136138
end;
137139
end;
138140

141+
class function TRTTI.CallMethod(aObject : TObject; const aMethodName : string; aParams : array of TValue) : TValue;
142+
var
143+
rtype : TRttiType;
144+
rmethod : TRttiMethod;
145+
rinstype: TRttiInstanceType;
146+
value : TValue;
147+
begin
148+
rtype := fCtx.GetType(aObject.ClassInfo);
149+
for rmethod in rtype.GetMethods do
150+
begin
151+
if CompareText(rmethod.Name,aMethodName) = 0 then
152+
begin
153+
rinstype := rtype.AsInstance;
154+
value := rmethod.Invoke(rinstype.MetaclassType,aParams);
155+
end;
156+
157+
end;
158+
end;
159+
139160
class destructor TRTTI.Destroy;
140161
begin
141162
fCtx.Free;

0 commit comments

Comments
 (0)