Starts the implementation (code) section of a Unit
 keyword Implementation(Unit UnitName;
The Implementation keyword starts the active code section of a unit - where the interface declarations are implemented.
A Delphi Unit is seen externally by its Interface declarations. Internally, these are implemented in the Implementation section. Only chnages to the Interface will cause a recompile of external units.
Within the Implementation section, the functions and procedures defined in the Interface section are coded. This section may have its own functions, procedures and data over and above that defined by the Interface. These are in effect private to the unit.
It may also have its own Uses statement, where Units are defined that are only used by the implementation. They are specific to the implementation, and external users of the Unit need not know about them.
Related commands
ConstStarts the definition of fixed data values
FunctionDefines a subroutine that returns a value
InterfaceUsed for Unit external definitions, and as a Class skeleton
ProcedureDefines a subroutine that does not return a value
TypeDefines a new category of variable or process
UnitDefines the start of a unit file - a Delphi module
UsesDeclares a list of Units to be imported
VarStarts the definition of a section of data variables
 Download this web site as a Windows program.

Example code : A simple example
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.

unit Unit1;

interface         // Defines the external view of this unit


  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);

  Form1: TForm1;

Implementation   // Implements the Interface of this unit
{$R *.dfm}       // Include form definitions

uses             // Private units

var              // Private variables
  msg : string;

const            // Private constants
  MSG_TEXT = 'Hello World';

// A private routine - not predefined in the Interface section
procedure SayHello;
  // Say hello to the World
  msg := MSG_TEXT;

// A routine pre-defined in the Interface section
procedure TForm1.FormCreate(Sender: TObject);
  // Say hello

  Hello World
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page