Vib*_*nRC 4 delphi rtti delphi-xe2
首先,在回答您的问题之前,请记住始终在与 Rtti 相关的问题中包含您的 delphi 版本。
1)假设您使用的是新版本的delphi(> = 2010),您可以使用属性获取类型的单元名称QualifiedName,从那里您必须检查属性IsInstance以确定是否是一个类。
检查下一个样本。
{$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 无法列出类的实例。因为 Rtti 是关于类型信息而不是实例信息。
| 归档时间: | 
 | 
| 查看次数: | 3639 次 | 
| 最近记录: |