GetImplementedInterfaces (Delphi)
Description
This example iterates through the types that have RTTI in the current application and displays the names of classes that implement interfaces. GetImplementedInterfaces is used to get the set of implemented interfaces for a specific type.
Code
program GetImplementedInterfaces;
{$APPTYPE CONSOLE}
uses
SysUtils,
Rtti;
var
LContext: TRttiContext;
LType: TRttiType;
LInstanceType: TRttiInstanceType;
LInterfaces: TArray<TRttiInterfaceType>;
begin
LContext := TRttiContext.Create;
{ Enumerate all types declared in the application }
for LType in LContext.GetTypes do
begin
if LType.IsInstance then
begin
LInstanceType := LType.AsInstance;
LInterfaces := LInstanceType.GetImplementedInterfaces;
if Length(LInterfaces) > 0 then
Writeln(LInstanceType.Name);
end;
end;
LContext.Free;
end.
Uses
- System.Rtti.TRttiInstanceType.GetImplementedInterfaces ( fr | de | ja )
- System.Rtti.TRttiInterfaceType ( fr | de | ja )
- System.Rtti.TRttiType.IsInstance ( fr | de | ja )
- System.Rtti.TRttiType.AsInstance ( fr | de | ja )