Declarations and Statements This topic describes the syntax of Delphi declarations and statements.
Aside from the uses clause (and reserved words like implementation that demarcate parts of a unit), a program
consists entirely of declarations and statements, which are organized into blocks.
This topic covers the following items:
Declarations Simple statements such as assignment
Structured statements such as conditional tests (e.g.,
if-then
, and case), iteration (e.g.,
for
, and
while
).
Declarations The names of variables, constants, types, fields, properties, procedures, functions, programs, units, libraries, and
packages are called identifiers. (Numeric constants like 26057 are not identifiers.) Identifiers must be declared before
you can use them; the only exceptions are a few predefined types, routines, and constants that the compiler
understands automatically, the variable
Result
when it occurs inside a function block, and the variable
Self
when
it occurs inside a method implementation.
A declaration defines an identifier and, where appropriate, allocates memory for it. For example,
var Size: Extended;
declares a variable called
Size
that holds an Extended (real) value, while
function DoThis(X, Y: string): Integer;
declares a function called
DoThis
that takes two strings as arguments and returns an integer. Each declaration
ends with a semicolon. When you declare several variables, constants, types, or labels at the same time, you need
only write the appropriate reserved word once:
var
Size: Extended;
Quantity: Integer;
Description: string
The syntax and placement of a declaration depend on the kind of identifier you are defining. In general, declarations
can occur only at the beginning of a block or at the beginning of the interface or implementation section of a unit
(after the uses clause). Specific conventions for declaring variables, constants, types, functions, and so forth are
explained in the documentation for those topics.