Skip to Content
Delphi in a Nutshell
book

Delphi in a Nutshell

by Ray Lischner
March 2000
Intermediate to advanced
576 pages
18h 13m
English
O'Reilly Media, Inc.
Content preview from Delphi in a Nutshell

Name

Protected Directive

Syntax

type Class declaration
protected
   Field declarations...
   Method and property declarations...
end;

Description

The protected directive introduces the protected section of a class declaration. Protected fields, methods, and properties are accessible only by methods of the class and its descendants. Classes and subroutines declared in the same unit can also access the protected declarations.

Tips and Tricks

  • Most methods or properties that are not part of the public interface should usually be made protected. When you declare a method as private, or do not have a protected property to access a private field, you are limiting the ways your class can be reused. You cannot predict the ways in which a class will be used in other projects, and hiding important declarations in a private section only frustrates would-be users of your class.

  • On the other hand, details of the implementation of a class must sometimes be kept private so you can be free to change the implementation in a future revision. Be sure to define appropriate protected methods to allow reuse of your class, even if the protected method merely calls a private method.

  • Many protected methods should be virtual. Because it is difficult to know how a subclass might want to extend or alter the behavior of an ancestor class, it is usually better to err on the side of too much flexibility. Make a protected method static only when you have a reason to do so.

Example

See the class keyword for an example.

See ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Delphi High Performance

Delphi High Performance

Primož Gabrijelčič
Delphi Cookbook

Delphi Cookbook

Daniele Teti

Publisher Resources

ISBN: 1565926595Errata Page