RAD Studio |  |

Understanding the Structure of a Package
Naming packages | Requires clause | Avoiding circular package references | Handling duplicate package references | Contains clause | Avoiding redundant source code uses | See Also
Collapse All

Packages include the following parts:

- Package name
- Requires clause
- Contains clause

Naming packages

Package names must be unique within a project. If you name a package Stats, RAD Studio generates a source file for it called Stats.dpk; the compiler generates an executable and a binary image called Stats.bpl and Stats.dcp, respectively. Use Stats to refer to the package in the requires clause of another package, or when using the package in an application.

Requires clause

The requires clause specifies other, external packages that are used by the current package. An external package included in the requires clause is automatically linked at compile time into any application that uses both the current package and one of the units contained in the external package.

If the unit files contained in your package make references to other packaged units, the other packages should appear in your package's requires clause or you should add them. If the other packages are omitted from the requires clause, the compiler will import them into your package 'implicitly contained units.'

Note: Most packages that you create require rtl. If using VCL components, you'll also need to include the vcl package.
Avoiding circular package references

Packages cannot contain circular references in their requires clause. This means that:

- A package cannot reference itself in its own requires clause.
- A chain of references must terminate without rereferencing any package in the chain. If package A requires package B, then package B cannot require package A; if package A requires package B and package B requires package C, then package C cannot require package A.

Handling duplicate package references

Duplicate references in a package's requires clause—or the Runtime Packages edit box—are ignored by the compiler. For programming clarity and readability, however, you should catch and remove duplicate package references.

Contains clause

The contains clause identifies the unit files to be bound into the package. If you are writing your own package, put your source code in pas files and include them in the contains clause.

Avoiding redundant source code uses

A package cannot appear in the containsclause of another package.

All units included directly in a package's contains clause, or included indirectly in any of those units, are bound into the package at compile time.

A unit cannot be contained (directly or indirectly) in more than one package used by the same application, including the IDE. This means that if you create a package that contains one of the units in vcl (VCL) you won't be able to install your package in the IDE. To use an already-packaged unit file in another package, put the first package in the second package's requires clause.

See Also

Working with Packages and Components: Overview

Creating and Editing Packages

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