Controlling Access

From RAD Studio
Jump to: navigation, search

Go Up to Object-oriented programming for component writers Index

There are five levels of access control --also called visibility--on properties, methods, and fields. Visibility determines which code can access which parts of the class. By specifying visibility, you define the interface to your components.

The following table shows the levels of visibility, from most restrictive to most accessible.

Levels of visibility within an object:

Visibility Meaning Used for


Accessible only to code in the unit where the class is defined.

Hiding Implementation Details


Accessible to code in the units where the class and its descendants are defined.

Defining the Component Writer's Interface


Accessible to all code.

Defining the Runtime Interface


Accessible to all code. Automation type information is generated.

OLE automation only


Accessible to all code and accessible from the Object Inspector. Saved in a form file.

Defining the Design-time Interface

Declare members as private if you want them to be available only within the class where they are defined; declare them as protected if you want them to be available only within that class and its descendants. Remember, though, that if a member is available anywhere within a unit file, it is available everywhere in that file. Thus, if you define two classes in the same unit, the classes will be able to access each other's private methods. And if you derive a class in a different unit from its ancestor, all the classes in the new unit will be able to access the ancestor's protected methods.

See Also