Name
Published Directive
Syntax
typeClass declarationpublishedField declarations...Method and property declarations...end;
Description
The published directive introduces the published
section of a class declaration. Just like public declarations,
published fields, methods, and properties are accessible from any
other subroutines or method in the same unit or in any unit that uses
the declaring unit (provided the class declaration is in the
unit’s interface section).
Tips and Tricks
The difference between public and published is that published declarations tell the compiler to store runtime type information about the published fields, methods, and properties.
The compiler treats a published section like public unless RTTI is enabled with the
$Mor$TypeInfocompiler directives, or if the class inherits from a class with RTTI enabled.TPersistentin Delphi’sClassesunit enables published RTTI, so all persistent classes (including all components, controls, and forms) have RTTI. The initial, unnamed section is published for classes with RTTI.Delphi’s IDE relies on the initial, unnamed section of a form class for storing its fields and methods. Although the compiler will let you move these declarations to any published section of the class, the IDE requires the declarations be in the unnamed section. Because forms and data modules have
TPersistentas an ancestor, the initial, unnamed section is published.Published fields must be of class type, and that class must also have RTTI enabled. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access