- 2.2.13.6. -
Table of Contents
2. TMT Pascal Language Description
2.2. Pascal Language Structure
2.2.13. OOP Extensions
2.2.13.6. Public and Private declarations
2.2.13.6. Public and Private
declarations
Public and private are standard directives in the Object Pascal
language. Treat them as if they were reserved words. For readability, it is
best to organize an object declaration by visibility, placing all the
private members together, followed by all the protected
members, and so on. This way each visibility reserved word appears at most
once and marks the beginning of a new section of the declaration. So a typical
object declaration should look like this:
type
TObject = object
private
{ Private declarations}
public
{ Public declarations }
end;
The scope of component identifiers declared in private component
sections are restricted to the module that contains the object type
declaration. Keep in mind that:
- Inside the module, private component identifiers act like
normal public component identifiers.
- Outside the module, private component identifiers are unknown
and inaccessible.
Use the public part to
- Declare data fields you want methods in objects in other units to access
- Declare methods you want objects in other units to access
Declarations in the private part are restricted in their access.
If you declare fields or methods to be private, they are unknown
and inaccessible outside the unit the object is defined in.
Use the private part to
- Declare data fields you want only methods in the current unit to access
- Declare methods you want only objects defined in the current unit to
access
- 2.2.13.6. -