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
- Navigate to Start | Programs | Embarcadero RAD Studio Sydney | Samples and open
F9or choose Run > Run.
The project has three source files:
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.