Delphi Programming Tutorials – 1.2 – Private, protected, public and published declarations
Delphi Programming Tutorials – 1.2 – Private, protected, public and published declarations.
Private, protected, public and published declarations.
- A class type declaration contains three or four possible sections that control the accessibility of its fields and methods.
- 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 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 ty 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.