I've recently been able to fetch a TRttiType for an interface using TRttiContext.FindType using Robert Loves "GetType"-workaround ("registering" the interface by an explicit call to ctx.GetType, e.g. RType := ctx.GetType(TypeInfo(IMyPrettyLittleInterface));).
One logical next step would be to iterate the methods of said interface. Consider
program rtti_sb_1;
{$APPTYPE CONSOLE}
uses
SysUtils, Rtti, mynamespace in 'mynamespace.pas';
var
ctx: TRttiContext;
RType: TRttiType;
Method: TRttiMethod;
begin
ctx := TRttiContext.Create;
RType := ctx.GetType(TypeInfo(IMyPrettyLittleInterface));
if RType <> nil then begin
for Method in RType.GetMethods do
WriteLn(Method.Name);
end;
ReadLn;
end.
This time, my mynamespace.pas
looks like this:
IMyPrettyLittleInterface = interface
['{6F89487E-5BB7-42FC-A760-38DA2329E0C5}']
procedure SomeProcedure;
end;
Unfortunately, RType.GetMethods
returns a zero-length TArray-instance. Are there anyone able to reproduce my troubles? (Note that in my example I've explicitly fetched the TRttiType using TRttiContext.GetType, not the workaround; the introduction is included to warn readers that there might be some unresolved issues regarding rtti and interfaces.) Thanks!