Please could someone explain me what's the difference between public and published class members in Delphi?
I tried to look at Delphi help and I understand that these members have the same visibility, but I don't understand very well how they differ and when should I use published members instead of public ones.
Thanks a lot.
TPersistent in Delphi's Classes unit 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.
type TAncestor = class; TAncestorClass = class of TAncestor; TAncestor = class public constructor Create; virtual; class function CreateClass(const AId: string): TAncestor; class procedure RegisterClass(const AId: string; const AType: TAncestorClass); end; class function TAncestor.
The compiler generates RTTI (Run-Time Type Information) metadata for published members, but not for public members (by default). The main effect of this is that the published properties of an object will appear in the Object Inspector at design time.
I do not know if you are writing components, but if you do, you probably know that properties and events are normally published, so that they can be set using the Object Inspector.
public property MyProperty: integer read FMyProperty write FMyProperty
MyProperty
will not be visible in the Object Inspector.
published property MyProperty: integer read FMyProperty write FMyProperty
MyProperty
will be visible in the Object Inspector.
Public properties and published properties have the same visibility, as you already stated. Published properties are included in RTTI, public properties aren't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With