【问题标题】:How to access a class property with rtti?如何使用 rtti 访问类属性?
【发布时间】:2017-11-17 08:54:56
【问题描述】:

是否可以通过 rtti 获得类属性?下面的代码有什么问题?

...
type
  TTest = class
  private
    class function GetCP: string; static;
  public
    class property CP: string read GetCP;
  end;

class function TTest.GetCP: string;
begin
  Result := 'ABC';
end;
...
procedure TForm1.Button5Click(Sender: TObject);
var
  oTest: TTest;
  oType: TRttiType;
begin
  oTest := TTest.Create;
  try
    oType := TRttiContext.Create.GetType(oTest.ClassType);
    ShowMessage(Length(oType.GetProperties).ToString);  // oType.GetProperties = nil !!! 
  finally
    oTest.Free;
  end;
end;  

TIA 和最好的问候, 布兰科

【问题讨论】:

    标签: delphi rtti


    【解决方案1】:

    类属性不能通过 RTTI 访问。

    【讨论】:

      猜你喜欢
      • 2010-11-14
      • 1970-01-01
      • 2016-06-10
      • 1970-01-01
      • 2012-07-06
      • 1970-01-01
      • 2014-09-07
      • 2014-03-12
      • 1970-01-01
      相关资源
      最近更新 更多