Run-Time Type Information

RTTI (Run-Time Type Information) allows your code to inspect types, objects, and metadata while the program is running.

Inspecting Types

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);
Result
Class Name: TUser

Attributes

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;
Result
Found column mapping: USERS

Related Reference

For detailed information on TTypeInfo members and the RTTIRawAttributes structure, see the reference documentation:

On this page