pyscripter 689 Posted December 30, 2022 (edited) In a 5 year old answer to a stackoverflow question @David Heffernan responded that "class properties cannot be accessed via RTTI". Is this still the case with recent versions of Delphi? Edited December 30, 2022 by pyscripter 1 Share this post Link to post
Remy Lebeau 1396 Posted December 30, 2022 (edited) AFAIK, yes, it is still the case. Edited December 30, 2022 by Remy Lebeau 1 1 Share this post Link to post
David Hoyle 68 Posted January 1, 2023 I can confirm that class variables and properties are not accessible in RS 11.2... Program ClassProppertyRTTI; {$APPTYPE CONSOLE} {$R *.res} Uses System.SysUtils, System.Rtti; Type TMyClass = Class Strict Private FGoodbye: Integer; Strict Private Class Var FHello: String; Strict Protected Public Class Property Hello: String Read FHello; Property Goodbye : Integer Read FGoodbye; End; Var C: TMyClass; Ctx: TRTTIContext; F : TRTTIField; T: TRttiType; P: TRttiProperty; Begin Try C := TMyClass.Create; Try Ctx := TRTTIContext.Create(); T := Ctx.GetType(C.ClassInfo); For F IN T.GetFields Do WriteLn('Field: ', F.Name); For P In T.GetProperties Do WriteLn('Property: ', P.Name); Finally C.Free; End; ReadLn; Except On E: Exception Do WriteLn(E.ClassName, ': ', E.Message); End; End. It only outputs FGoodbye and Goodbye. I didn't actually know this restriction in the RTTI. 1 Share this post Link to post
programmerdelphi2k 237 Posted January 1, 2023 (edited) In fact, no information is generated for "class var/procedure/function" in RAD 11.2 {$M+} TMyClass = class private FPrivatedField: string; procedure FProcedurePrivatedField(const AValue: string); class var FClassVarPrivatedField: string; class procedure FClassProcedurePrivatedField(const AValue: string); static; protected FProtectedField: string; procedure FProcedureProtectedField(const AValue: string); class var FClassVarProtectedField: string; class procedure FClassProcedureProtectedField(const AValue: string); static; public FPublicatedField: string; procedure FProcedurePublicField(const AValue: string); class var FClassVarPublicField: string; class procedure FClassProcedurePublicField(const AValue: string); static; published FPublishedField: TMyPublished; procedure FProcedurePublishedField(const AValue: TMyPublished); class var FClassVarPublishedField: TMyPublished; class procedure FClassProcedurePublishedField(const AValue: TMyPublished); static; public class property ClassVarPrivatedField : string read FClassVarPrivatedField write FClassProcedurePrivatedField; class property ClassVarProtectedField : string read FClassVarProtectedField write FClassProcedureProtectedField; class property ClassVarPublicatedField: string read FClassVarPublicField write FClassProcedurePublicField; class property ClassVarPublishedField : TMyPublished read FClassVarPublishedField write FClassProcedurePublishedField; // property PrivatedField : string read FPrivatedField write FProcedurePrivatedField; property ProtectedField : string read FProtectedField write FProcedureProtectedField; property PublicatedField: string read FPublicatedField write FProcedurePublicField; property PublishedField : TMyPublished read FPublishedField write FProcedurePublishedField; end; {$M-} Quote Fields: mvPrivate,FPrivatedField mvProtected,FProtectedField mvPublic,FPublicatedField mvPublished,FPublishedField Methods: Method: Contructor,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkConstructor,dkStatic,-12,Create Method: xxxxxxxxxx,Destructor,xxxxxxxxxxxx,xxxxxx,mvPublic,mkDestructor,dkVtable,-1,Destroy Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,Static,mvPublic,mkClassProcedure,dkStatic,-12,FClassProcedurePublicField Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,Static,mvPublished,mkClassProcedure,dkStatic,-12,FClassProcedurePublishedField Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,ClassInfo Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,ClassName Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,ClassNameIs Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,ClassParent Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,GetInterfaceEntry Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,GetInterfaceTable Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,InheritsFrom Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,InitInstance Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,InstanceSize Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,MethodAddress Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,MethodAddress Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,MethodName Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,QualifiedClassName Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,UnitName Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkStatic,-12,UnitScope Method: xxxxxxxxxx,xxxxxxxxxx,Class Method,xxxxxx,mvPublic,mkClassFunction,dkVtable,-3,NewInstance Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkFunction,dkStatic,-12,ClassType Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkFunction,dkStatic,-12,FieldAddress Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkFunction,dkStatic,-12,FieldAddress Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkFunction,dkStatic,-12,GetInterface Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkFunction,dkVtable,-10,GetHashCode Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkFunction,dkVtable,-11,Equals Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkFunction,dkVtable,-8,SafeCallException Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkFunction,dkVtable,-9,ToString Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkProcedure,dkStatic,-12,CleanupInstance Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkProcedure,dkStatic,-12,DisposeOf Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkProcedure,dkStatic,-12,FProcedurePublicField Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkProcedure,dkStatic,-12,Free Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkProcedure,dkVtable,-2,FreeInstance Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkProcedure,dkVtable,-4,DefaultHandler Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkProcedure,dkVtable,-5,Dispatch Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkProcedure,dkVtable,-6,BeforeDestruction Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublic,mkProcedure,dkVtable,-7,AfterConstruction Method: xxxxxxxxxx,xxxxxxxxxx,xxxxxxxxxxxx,xxxxxx,mvPublished,mkProcedure,dkStatic,-12,FProcedurePublishedField Properties: mvPublic,PrivatedField mvPublic,ProtectedField mvPublic,PublicatedField mvPublic,PublishedField Edited January 1, 2023 by programmerdelphi2k 1 Share this post Link to post