RTTI (Run-Time Type Information) allows your code to inspect types, objects, and metadata while the program is running.
You can get type information using TypeOf (for class symbols).
type
TUser = class
Name : String;
end;
var info := TypeOf(TUser);
PrintLn('Class Name: ' + info.Name); Class Name: TUser
Attributes attach metadata to symbols.
type
ColumnAttribute = class(TCustomAttribute)
FName : String;
constructor Create(const name : String); begin FName := name; end;
end;
type
[ColumnAttribute('USERS')]
TUserWithAttr = class
Name : String;
end;
// Iterate through attributes
var attrs := RTTIRawAttributes;
for var i := 0 to attrs.Length - 1 do begin
if attrs[i].T = TypeOf(TUserWithAttr) then begin
if attrs[i].A is ColumnAttribute then
PrintLn('Found column mapping: ' + ColumnAttribute(attrs[i].A).FName);
end;
end; Found column mapping: USERS
For detailed information on TTypeInfo members and the RTTIRawAttributes structure, see the reference documentation: