1.2.47 $M or $TYPEINFO : Generate type info

For classes that are compiled in the {$M+} or {$TYPEINFO ON} state, the compiler will generate Run-Time Type Information (RTTI). All descendent class of a class that was compiled in the {$M+} state will get RTTI information too. Any class that is used as a field or property in a published section will also get RTTI information.

By default, no Run-Time Type Information is generated for published sections, making them equivalent to public sections. Only when a class (or one of its parent classes) was compiled in the {$M+} state, the compiler will generate RTTI for the methods and properties in the published section.

The TPersistent object that is present in the classes unit (part of the RTL) is generated in the {$M+} state. The generation of RTTI allows programmers to stream objects, and to access published properties of objects, without knowing the actual class of the object.

The run-time type information is accessible through the TypInfo unit, which is part of the Free Pascal Run-Time Library.

Remark: The streaming system implemented by Free Pascal requires that all streamable components be descendent from TPersistent. It is possible to create classes with published sections that do not descend from TPersistent, but those classes will not be streamed correctly by the streaming system of the Classes unit.