Show: Delphi C++
Display Preferences

RTTI directive (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Delphi Compiler Directives (List) Index

Type

Expression

Syntax

{$RTTI INHERIT|EXPLICIT [visibility clause]}

Scope

Local

Syntax

The general syntax of the $RTTI directive can be split into three parts. The basic form of $RTTI is as follows:

{$RTTI INHERIT|EXPLICIT [visibility-clause]}

visibility-clause:

METHODS|PROPERTIES|FIELDS (visibility-expression)

visibility-expression:

 [vcPrivate],[vcProtected], [vcPublic], [vcPublished];


Description

The $RTTI directive is used to control the amount of extended RTTI (Run-Time Type Information) information that is emitted for a class or record type. The basic idea is to give the developer the power to selectively enable or disable extended RTTI for certain class or record members.

The INHERIT RTTI mode allows for classes to inherit the specified RTTI options from the base class. For example:

 {$RTTI INHERIT}
 TDerivative = class(TBase)
 ...
 end;

ensures that all RTTI options for TDerivative are inherited from the base class TBase. To inherit only certain information, you can write a more complex directive:

 {$RTTI INHERIT METHODS([vcPublic, vcPublished]) PROPERTIES([vcPublic, vcPublished])}
 TDerivative = class(TBase)
 ...
 end;

that inherits RTTI options only for public and published methods and properties. INHERIT cannot be used for record types, because records cannot be derived and do not have ancestors.

To explicitly override the inherited RTTI options, use the EXPLICIT mode. Once used, EXPLICIT negates all inherited options and sets new ones:

 {$RTTI EXPLICIT METHODS([vcPublished]) PROPERTIES([vcPublished])}
 TDerivative = class(TBase)
 ...
 end;

The previous example disables all the inherited RTTI options and defines new ones, in which only published methods and properties have extended RTTI.

To disable all extended RTTI information for a given class or record, you can write an RTTI directive like the following:

 {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}

that disables all the inherited RTTI options and sets the new ones to not emit any extended RTTI information.

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance