Browse Source

+ add TRttiType.GetMethod to find a method by name

git-svn-id: trunk@39884 -
svenbarth 6 years ago
parent
commit
bb11ec6375
1 changed files with 13 additions and 0 deletions
  1. 13 0
      packages/rtl-objpas/src/inc/rtti.pp

+ 13 - 0
packages/rtl-objpas/src/inc/rtti.pp

@@ -197,6 +197,7 @@ type
     function GetProperties: specialize TArray<TRttiProperty>; virtual;
     function GetProperties: specialize TArray<TRttiProperty>; virtual;
     function GetProperty(const AName: string): TRttiProperty; virtual;
     function GetProperty(const AName: string): TRttiProperty; virtual;
     function GetMethods: specialize TArray<TRttiMethod>; virtual;
     function GetMethods: specialize TArray<TRttiMethod>; virtual;
+    function GetMethod(const aName: String): TRttiMethod; virtual;
     function GetDeclaredMethods: specialize TArray<TRttiMethod>; virtual;
     function GetDeclaredMethods: specialize TArray<TRttiMethod>; virtual;
     property IsInstance: boolean read GetIsInstance;
     property IsInstance: boolean read GetIsInstance;
     property isManaged: boolean read GetIsManaged;
     property isManaged: boolean read GetIsManaged;
@@ -2608,6 +2609,18 @@ begin
   Result := fMethods;
   Result := fMethods;
 end;
 end;
 
 
+function TRttiType.GetMethod(const aName: String): TRttiMethod;
+var
+  methods: specialize TArray<TRttiMethod>;
+  method: TRttiMethod;
+begin
+  methods := GetMethods;
+  for method in methods do
+    if SameText(method.Name, AName) then
+      Exit(method);
+  Result := Nil;
+end;
+
 function TRttiType.GetDeclaredMethods: specialize TArray<TRttiMethod>;
 function TRttiType.GetDeclaredMethods: specialize TArray<TRttiMethod>;
 begin
 begin
   Result := Nil;
   Result := Nil;