Quick start manual

4-30
Delphi Language Guide
Blocks
A block consists of a series of declarations followed by a compound statement. All
declarations must occur together at the beginning of the block. So the form of a block
is
declarations
begin
statements
end
The declarations section can include, in any order, declarations for variables, constants
(including resource strings), types, procedures, functions, and labels. In a program
block, the declarations section can also include one or more exports clauses (see
Chapter 9, “Libraries and packages”).
For example, in a function declaration like
function UpperCase(const S: string): string;
var
Ch: Char;
L: Integer;
Source, Dest: PChar;
begin
ƒ
end;
the first line of the declaration is the function heading and all of the succeeding lines
make up the block. Ch, L, Source, and Dest are local variables; their declarations apply
only to the UpperCase function block and override—in this block only—any
declarations of the same identifiers that may occur in the program block or in the
interface or implementation section of a unit.
Scope
An identifier, such as a variable or function name, can be used only within the scope
of its declaration. The location of a declaration determines its scope. An identifier
declared within the declaration of a program, function, or procedure has a scope
limited to the block in which it is declared. An identifier declared in the interface
section of a unit has a scope that includes any other units or programs that use the
unit where the declaration occurs. Identifiers with narrower scope—especially
identifiers declared in functions and procedures—are sometimes called local, while
identifiers with wider scope are called global.