RAD Studio
ContentsIndex
PreviousUpNext
Controlling Access

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 table below shows the levels of visibility, from most restrictive to most accessible:  

Levels of visibility within an object  

Visibility 
Meaning 
Used for 
private  
Accessible only to code in the unit where the class is defined.  
protected  
Accessible to code in the unit(s) where the class and its descendants are defined.  
public  
Accessible to all code.  
automated  
Accessible to all code. Automation type information is generated.  
OLE automation only.  
published  
Accessible to all code and accessible from the Object Inspector. Saved in a form file.  

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.

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