Quick start manual

6-6
Delphi Language Guide
Declaring procedures and functions
The directives near, far, and export refer to calling conventions in 16-bit Windows
programming. They have no effect in 32-bit applications and are maintained for
backward compatibility only.
Forward and interface declarations
The forward directive replaces the block, including local variable declarations and
statements, in a procedure or function declaration. For example,
function Calculate(X, Y: Integer): Real; forward;
declares a function called Calculate. Somewhere after the forward declaration, the
routine must be redeclared in a defining declaration that includes a block. The defining
declaration for Calculate might look like this:
function Calculate;
ƒ { declarations }
begin
ƒ { statement block }
end;
Ordinarily, a defining declaration does not have to repeat the routine’s parameter list
or return type, but if it does repeat them, they must match those in the forward
declaration exactly (except that default parameters can be omitted). If the forward
declaration specifies an overloaded procedure or function (see “Overloading
procedures and functions” on page 6-8), then the defining declaration must repeat
the parameter list.
A forward declaration and its defining declaration must appear in the same type
declaration section. That is, you can’t add a new section (such as a var section or
const section) between the forward declaration and the defining declaration. The
defining declaration can be an external or assembler declaration, but it cannot be
another forward declaration.
The purpose of a forward declaration is to extend the scope of a procedure or
function identifier to an earlier point in the source code. This allows other procedures
and functions to call the forward-declared routine before it is actually defined.
Besides letting you organize your code more flexibly, forward declarations are
sometimes necessary for mutual recursions.
The forward directive has no effect in the interface section of a unit. Procedure and
function headers in the interface section behave like forward declarations and must
have defining declarations in the implementation section. A routine declared in the
interface section is available from anywhere else in the unit and from any other unit
or program that uses the unit where it is declared.
External declarations
The external directive, which replaces the block in a procedure or function
declaration, allows you to call routines that are compiled separately from your
program. External routines can come from object files or dynamically loadable
libraries.