Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a class property with rtti?

Tags:

delphi

rtti

Is it possible to get a class property with a rtti? What's wrong with the code below?

...
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 and best regards, Branko

like image 479
Branko Avatar asked Oct 24 '25 14:10

Branko


1 Answers

Class properties cannot be accessed via RTTI.

like image 58
David Heffernan Avatar answered Oct 26 '25 04:10

David Heffernan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!