Quellcode durchsuchen

+ add method to query the method count of an interface

git-svn-id: trunk@37761 -
svenbarth vor 7 Jahren
Ursprung
Commit
f8c5272b8f
1 geänderte Dateien mit 31 neuen und 0 gelöschten Zeilen
  1. 31 0
      packages/rtl-objpas/src/inc/rtti.pp

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

@@ -334,6 +334,8 @@ type
 
   TRttiInterfaceType = class(TRttiType)
   protected
+    function IntfMethodCount: Word;
+    function MethodTable: PIntfMethodTable; virtual; abstract;
     function GetBaseType: TRttiType; override;
     function GetIntfBaseType: TRttiInterfaceType; virtual; abstract;
     function GetDeclaringUnitName: String; virtual; abstract;
@@ -494,6 +496,7 @@ type
   private
     function IntfData: PInterfaceData; inline;
   protected
+    function MethodTable: PIntfMethodTable; override;
     function GetIntfBaseType: TRttiInterfaceType; override;
     function GetDeclaringUnitName: String; override;
     function GetGUID: TGUID; override;
@@ -505,6 +508,7 @@ type
   private
     function IntfData: PInterfaceRawData; inline;
   protected
+    function MethodTable: PIntfMethodTable; override;
     function GetIntfBaseType: TRttiInterfaceType; override;
     function GetDeclaringUnitName: String; override;
     function GetGUID: TGUID; override;
@@ -1032,6 +1036,11 @@ begin
   Result := PInterfaceData(FTypeData);
 end;
 
+function TRttiRefCountedInterfaceType.MethodTable: PIntfMethodTable;
+begin
+  Result := IntfData^.MethodTable;
+end;
+
 function TRttiRefCountedInterfaceType.GetIntfBaseType: TRttiInterfaceType;
 var
   context: TRttiContext;
@@ -1074,6 +1083,12 @@ begin
   Result := PInterfaceRawData(FTypeData);
 end;
 
+function TRttiRawInterfaceType.MethodTable: PIntfMethodTable;
+begin
+  { currently there is none! }
+  Result := Nil;
+end;
+
 function TRttiRawInterfaceType.GetIntfBaseType: TRttiInterfaceType;
 var
   context: TRttiContext;
@@ -2106,6 +2121,22 @@ end;
 
 { TRttiInterfaceType }
 
+function TRttiInterfaceType.IntfMethodCount: Word;
+var
+  parent: TRttiInterfaceType;
+  table: PIntfMethodTable;
+begin
+  parent := GetIntfBaseType;
+  if Assigned(parent) then
+    Result := parent.IntfMethodCount
+  else
+    Result := 0;
+
+  table := MethodTable;
+  if Assigned(table) then
+    Inc(Result, table^.Count);
+end;
+
 function TRttiInterfaceType.GetBaseType: TRttiType;
 begin
   Result := GetIntfBaseType;