Show: Delphi C++
Display Preferences

Run-Time Type Information (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Delphi Compiler Directives (List) Index

Type

Switch

Syntax

{$M+} or {$M-}

{$TYPEINFO ON} or {$TYPEINFO OFF}

Default

{$M-}

{$TYPEINFO OFF}

Scope

Local



The {$M} switch directive controls generation of run-time type information (RTTI). When a class is declared in the {$M+} state, or is derived from a class that was declared in the {$M+} state, the compiler generates run-time type information for properties and events that are declared in a published section. If a class is declared in the {$M+} state, and is not derived from a class that was declared in the {$M} state, published sections are not allowed in the class. Note that if a class is forward declared, the first declaration of the class must be declared with the $M switch.

When the $M switch is used to declare an interface, the compiler generates run-time type information for all properties. That is, for interfaces, all members are treated as if they were published.

Note: The TPersistent class defined in the Classes unit of the component library is declared in the {$M+} state, so any class derived from TPersistent will have RTTI generated for its published sections. The component library uses the run-time type information generated for published sections to access the values of a component's properties when saving or loading form files. Furthermore, the IDE uses a component's run-time type information to determine the list of properties to show in the Object Inspector.
Note: The IInvokable interface defined in the System unit is declared in the {$M+} state, so any interface derived from IInvokable will have RTTI generated. The routines in the IntfInfo unit can be used to retrieved the RTTI.

There is seldom, if ever, any need for an application to directly use the {$M}compiler switch.

See Also

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