【发布时间】: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 和最好的问候, 布兰科
【问题讨论】: