Show: Delphi C++
Display Preferences

Understanding the Structure of a Package

From RAD Studio
Jump to: navigation, search

Go Up to Creating and Editing Packages


Packages include the following parts:

Package Names

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 contains clause 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

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance