Identifiers are valid from the point of their declaration until the end of the block in which the declaration occurred. The range where the identifier is known is the scope of the identifier. The exact scope of an identifier depends on the way it was defined.
The scope of a variable declared in the declaration part of a block, is valid from the point of declaration until the end of the block.
If a block contains a second block, in which the identfier is redeclared, then inside this block, the second declaration will be valid. Upon leaving the inner block, the first declaration is valid again.
Consider the following example:
In this example, inside the procedure, X denotes an integer variable.
It has it's own storage space, independent of the variable X outside
the procedure.
The field identifiers inside a record definition are valid in the following places:
A component identifier is valid in the following places:
Note that method designators are also considered identifiers.
All identifiers in the interface part of a unit are valid from the point of declaration, until the end of the unit. Furthermore, the identifiers are known in programs or units that have the unit in their uses clause. Identifiers from indirectly dependent units are not available.
Identifiers declared in the implementation part of a unit are valid from the point of declaration to the end of the unit.
The system unit is automatically used in all units and programs. It's identifiers are therefore always known, in each program or unit you make.
The rules of unit scope implie that you can redefine an identifier of a unit. To have access to an identifier of another unit that was redeclared in the current unit, precede it with that other units name, as in the following example:
This is especially useful if you redeclare the system unit's identifiers.