有没有可能用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;
字符串
最好的问候,布兰科
2条答案
按热度按时间wkyowqbh1#
无法通过RTTI访问类属性。
zd287kbt2#
我用这个函数获取类属性:
字符串