Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between public and published class members in Delphi?

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.

like image 310
Ondra C. Avatar asked Jul 01 '10 12:07

Ondra C.


People also ask

What is published in Delphi?

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.

How do I create an instance of a class in Delphi?

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.


2 Answers

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

public   property MyProperty: integer read FMyProperty write FMyProperty 

MyProperty will not be visible in the Object Inspector.

Published

published   property MyProperty: integer read FMyProperty write FMyProperty 

MyProperty will be visible in the Object Inspector.

like image 56
Andreas Rejbrand Avatar answered Sep 22 '22 07:09

Andreas Rejbrand


Public properties and published properties have the same visibility, as you already stated. Published properties are included in RTTI, public properties aren't.

like image 22
R-D Avatar answered Sep 21 '22 07:09

R-D