RTTI enables you to easily retrieve details on
the methods, fields and properties of a class.
TRttiType =
class(TRttiNamedObject)
public
...
function GetMethods: TArray<TRttiMethod>; overload;
virtual;
function GetFields: TArray<TRttiField>; virtual;
function GetProperties: TArray<TRttiProperty>;
virtual;
function GetMethod(const AName: string): TRttiMethod;
virtual;
function GetMethods(const AName: string):
TArray<TRttiMethod>; overload; virtual;
function GetField(const AName: string): TRttiField;
virtual;
function GetProperty(const AName: string): TRttiProperty;
virtual;
function GetDeclaredMethods: TArray<TRttiMethod>;
virtual;
function GetDeclaredProperties: TArray<TRttiProperty>;
virtual;
function GetDeclaredFields: TArray<TRttiField>;
virtual;
// The ancestor for types with ancestors.
property BaseType: TRttiType read GetBaseType;
...
end;
It provides methods to easily get or set the
value of a field.
TRttiField =
class(TRttiMember)
public
...
property FieldType: TRttiType read GetFieldType;
function GetValue(Instance: Pointer): TValue; virtual;
procedure SetValue(Instance: Pointer; const AValue: TValue);
virtual;
function ToString: string; override;
...
end;
Information on class methods including their
return types and parameters can be easily discovered. Invoking the
method is also made easy.
TRttiMethod =
class(TRttiMember)
public
...
function Invoke(Instance: TObject; const Args: array of
TValue): TValue; overload;
function GetParameters: TArray<TRttiParameter>;
virtual; abstract;
function ToString: string; override;
property ReturnType: TRttiType read GetReturnType;
property IsConstructor: Boolean read GetIsConstructor;
property IsDestructor: Boolean read GetIsDestructor;
...
end;