Name

Unit Keyword

Syntax

unit Name;
interface
  Declarations...
implementation
  Declarations...
initialization
  Statements...
finalization
  Statements...
end.

unit Name;
interface
  Declarations...
implementation
  Declarations...
begin
  Statements...
end.

Description

The unit keyword introduces a unit, which is Delphi’s basic module for building programs. A unit’s name must match the filename (with a .pas extension). Chapter 2 has more information about units.

Tips and Tricks

  • The interface or implementation sections can each have a uses declaration. If so, the uses declaration must appear first in the section.

  • The initialization and finalization sections are optional. If a unit has a finalization section, it must have an initialization section, even if the initialization section is empty.

  • You can use the begin keyword instead of initialization, but if you do, the unit cannot have a finalization section.

See Also

Begin Keyword, End Keyword, Finalization Keyword, Implementation Keyword, Initialization Keyword, Interface Keyword, Uses Keyword

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.