Quick start manual

Syntactic elements
4-31
The rules that determine identifier scope are summarized below.
Naming conflicts
When one block encloses another, the former is called the outer block and the latter the
inner block. If an identifier declared in an outer block is redeclared in an inner block,
the inner declaration takes precedence over the outer one and determines the
meaning of the identifier for the duration of the inner block. For example, if you
declare a variable called MaxValue in the interface section of a unit, and then declare
another variable with the same name in a function declaration within that unit, any
unqualified occurrences of MaxValue in the function block are governed by the
second, local declaration. Similarly, a function declared within another function
creates a new, inner scope in which identifiers used by the outer function can be
redeclared locally.
The use of multiple units further complicates the definition of scope. Each unit listed
in a uses clause imposes a new scope that encloses the remaining units used and the
program or unit containing the uses clause. The first unit in a uses clause represents
the outermost scope and each succeeding unit represents a new scope inside the
previous one. If two or more units declare the same identifier in their interface
sections, an unqualified reference to the identifier selects the declaration in the
innermost scope—that is, in the unit where the reference itself occurs, or, if that unit
doesn’t declare the identifier, in the last unit in the uses clause that does declare the
identifier.
If the identifier is declared in ... its scope extends ...
the declaration section of a program, function,
or procedure
from the point where it is declared to the end of
the current block, including all blocks enclosed
within that scope.
the interface section of a unit from the point where it is declared to the end of
the unit, and to any other unit or program that
uses that unit. (See Chapter 3, “Programs and
units”.)
the implementation section of a unit, but not
within the block of any function or procedure
from the point where it is declared to the end of
the unit. The identifier is available to any
function or procedure in the unit, including the
initialization and finalization sections, if present.
the definition of a record type (that is, the
identifier is the name of a field in the record)
from the point of its declaration to the end of the
record-type definition. (See “Records” on
page 5-23.)
the definition of a class (that is, the identifier is
the name of a data field property or method in
the class)
from the point of its declaration to the end of the
class-type definition, and also includes
descendants of the class and the blocks of all
methods in the class and its descendants. (See
Chapter 7, “Classes and objects”.)