RTL.AttributesAndRTTI Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use the RTTI API.


You can find the AttributesAndRTTI sample project at:

  • Start > Programs > Embarcadero RAD Studio > Samples > Delphi > RTL > AttributesAndRTTI > rtti_browser
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.


Rtti_browser is a VCL application that displays the hierarchy of the public types available in the current RTTI context. Clicking a class, method, property, or parameter in the tree view displays all their RTTI properties in the list view below.

How to Use the Sample

  1. Navigate to Start | Programs | Embarcadero RAD Studio Athens | Samples and open rtti_browser.dproj.
  2. Press F9 or choose Run > Run.


The project has three source files:

File Contains


The implementation of MyDemoAttribute, a user-defined custom attribute, and of TDemoObject, the corresponding annotated class.


TMainForm, the class corresponding to the main form.


  • MyDemoAttribute, derived from TCustomAttribute, provides two constructors that can be used to annotate a class or its members.
  • TDemoObject is a demo class with one field and one procedure. The class, the field, the procedure, and the parameter of the procedure are all annotated using MyDemoAttribute.
  • TMainForm retrieves all the RTTI information from the context and displays it on the form.


  • A TRttiContext object is used to get type information for all the public types.
  • The ListAttributes method gets all the fields, properties, methods, and parameters and, for each of them, it displays the corresponding attribute values.
  • TRttiType.QualifiedName is used to get the qualified name for a class. For the other RTTI objects (methods, parameters, fields, and properties), their qualified name is obtained by concatenating the qualified name of their parent with their own name.
  • The hierarchy of types is displayed using a TTreeView component and the properties for each node are displayed using a TListView component.


See Also