Package Declarations and Source Files

Each package is declared in a separate source file, which should be saved with the .dpk extension to avoid confusion with other files containing Delphi code. A package source file does not contain type, data, procedure, or function declarations. Instead, it contains:

  • a name for the package.
  • a list of other packages required by the new package. These are packages to which the new package is linked.
  • a list of unit files contained by, or bound into, the package when it is compiled. The package is essentially a wrapper for these source-code units, which provide the functionality of the compiled package.

A package declaration has the form packagepackageName;

requiresClause;

containsClause;

end.

where packageName is any valid identifier. The requiresClause and containsClause are both optional. For example, the following code declares the datax package.

package DATAX; requires rtl, contains Db, DBLocal, DBXpress, ... ; end.

The requires clause lists other, external packages used by the package being declared. It consists of the directive requires, followed by a comma-delimited list of package names, followed by a semicolon. If a package does not reference other packages, it does not need a requires clause.

The contains clause identifies the unit files to be compiled and bound into the package. It consists of the directive contains, followed by a comma-delimited list of unit names, followed by a semicolon. Any unit name may be followed by the reserved word in and the name of a source file, with or without a directory path, in single quotation marks; directory paths can be absolute or relative. For example, contains MyUnit in 'C:\MyProject\MyUnit.pas';

Note: Thread-local variables (declared with threadvar) in a packaged unit cannot be accessed from clients that use the package.

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment