RAD Studio |  |

Private, Protected, Public, and Published Declarations
See Also
Collapse All

A class type declaration contains three or four possible sections that control the accessibility of its fields and methods:

Copy Code

    Type
      TClassName = Class(TObject)
        public
          {public fields}
          {public methods}
        protected
          {protected fields}
          {protected methods}
        private
          {private fields}
          {private methods}
    end;

- The public section declares fields and methods with no access restrictions. Class instances and descendant classes can access these fields and methods. A public member is accessible from wherever the class it belongs to is accessible—that is, from the unit where the class is declared and from any unit that uses that unit.
- The protected section includes fields and methods with some access restrictions. A protected member is accessible within the unit where its class is declared and by any descendant class, regardless of the descendant class's unit.
- The private section declares fields and methods that have rigorous access restrictions. A private member is accessible only within the unit where it is declared. Private members are often used in a class to implement other (public or published) methods and properties.
- For classes that descend from TPersistent, a published section declares properties and events that are available at design time. A published member has the same visibility as a public member, but the compiler generates runtime type information for published members. Published properties appear in the Object Inspector at design time.

When you declare a field, property, or method, the new member is added to one of these four sections, which gives it its visibility: private, protected, public, or published.
See Also

Object Pascal and the Class Libraries

Properties

Scope and Qualifiers

Defining New Classes

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!