Delphi 如何使用rtti访问类属性?
是否可以使用rtti获取类属性?下面的代码有什么问题Delphi 如何使用rtti访问类属性?,delphi,rtti,Delphi,Rtti,是否可以使用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.
...
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;
致以最诚挚的问候,
Branko无法通过RTTI访问类属性