Before answering your question, remember that always include the delphi version in questions related to Rtti.
1) When using the new version of delphi (> = 2010) you can get the name of the unit of type using QualifiedName , from there you should check the IsInstance property to determine if the class is.
Check out the following sample.
{$APPTYPE CONSOLE} {$R *.res} uses Rtti, System.SysUtils; procedure Test; Var t : TRttiType; //extract the unit name from the QualifiedName property function GetUnitName(lType: TRttiType): string; begin Result := StringReplace(lType.QualifiedName, '.' + lType.Name, '',[rfReplaceAll]) end; begin //list all the types of the System.SysUtils unit for t in TRttiContext.Create.GetTypes do if SameText('System.SysUtils',GetUnitName(t)) and (t.IsInstance) then Writeln(t.Name); end; begin try Test; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln; end.
2) Rtti cannot list instances of classes. because Rtti is type information, not instances.
source share