Quick start manual
7-4
Delphi Language Guide
Class types
Object types
As an alternative to class types, you can declare object types using the syntax
type objectTypeName = object (ancestorObjectType)
memberList
end;
where objectTypeName is any valid identifier, (ancestorObjectType) is optional, and
memberList declares fields, methods, and properties. If (ancestorObjectType) is
omitted, then the new type has no ancestor. Object types cannot have published
members.
Since object types do not descend from TObject, they provide no built-in constructors,
destructors, or other methods. You can create instances of an object type using the
New procedure and destroy them with the Dispose procedure, or you can simply
declare variables of an object type, just as you would with records.
Object types are supported for backward compatibility only. Their use is not
recommended.
Visibility of class members
Every member of a class has an attribute called visibility, which is indicated by one of
the reserved words private, protected, public, published, or automated. For
example,
published property Color: TColor read GetColor write SetColor;
declares a published property called Color. Visibility determines where and how a
member can be accessed, with private representing the least accessibility, protected
representing an intermediate level of accessibility, and public, published, and
automated representing the greatest accessibility.
If a member’s declaration appears without its own visibility specifier, the member
has the same visibility as the one that precedes it. Members at the beginning of a class
declaration that don’t have a specified visibility are by default published, provided
the class is compiled in the {$M+} state or is derived from a class compiled in the
{$M+} state; otherwise, such members are public.
For readability, it is best to organize a class declaration by visibility, placing all the
private members together, followed by all the protected members, and so forth. This
way each visibility reserved word appears at most once and marks the beginning of a
new “section” of the declaration. So a typical class declaration should like this:
type
TMyClass = class(TControl)
private
ƒ { private declarations here}
protected
ƒ { protected declarations here }
public
ƒ { public declarations here }
published
ƒ { published declarations here }
end;