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

Ondra C. picture Ondra C. · Jul 1, 2010 · Viewed 15.9k times · Source

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.

Answer

Andreas Rejbrand picture Andreas Rejbrand · Jul 1, 2010

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.