Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
Definitions of PRIVATE, PROTECTED, PUBLIC, and PUBLISHED sections of a unit Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delphi All Versions
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: Lou Adler

What do the PRIVATE, PROTECTED, PUBLIC and PUBLISHED sections of a unit mean?


They define the level of visibility of properties and methods of an object. In a 
nutshell, they are as follows:

PRIVATE - Things contained in this section are private to the object. External 
objects do not have access to any elements contained here.

PROTECTED - Similar to private with one exception: Descendants of the object have 
access to the methods and properties contained here.

PUBLIC - All external objects have access to elements here.

PUBLISHED - Similar to PUBLIC, but properties listed here show up at design time 
under the Object Inspector.

These sections really come into play when you're building components. Typically, 
you'll put the local field variables assigned to properties in the PRIVATE section, 
along with functions and procedures that act only within the scope of the object 
itself. In the PROTECTED methods, if you know the object will be inherited at some 
point, you'll put properties, functions and procedures to give access to your 
descendants, but maintain privacy from external objects. In the PUBLIC section, 
you'll place methods and procedures that usually don't have a corresponding 
property, but require full access by other entities; or, insert properties that you 
don't want visible in the Object Inspector. The PUBLISHED section by convention is 
for properties only, though I've put procedures there just to see if I still had 
access to them.

TForms have PRIVATE and PUBLIC sections as well. In most cases you won't put them 
to use; however, there will be times when you want to add functionality and 
capabilities to the form that need to be assigned levels of visibility.

Play around with this stuff. The more you understand it, the more you'll understand object-oriented programming. By the way, I suggest getting a book on general object-oriented programming principles. Understanding the theory behind objects will help you get a better handle on Delphi programming.

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC