From Lazarus wiki
Revision as of 12:56, 21 August 2019 by Kai Burghardt (talk | contribs) (complete rewrite)
Jump to navigationJump to search

Deutsch (de) English (en) español (es) suomi (fi) français (fr) 日本語 (ja)

The uses clause of a Pascal module imports exported identifiers from another module. It was introduced by UCSD Pascal and virtually every modern Pascal compiler, including FPC, supports it, if no other mechanism is available.

Uses is a reserved word.



Every Pascal module – i. e. program, unit, or library – can have at most one uses clause. It has to appear right after the module header, after any global compiler directives.


The uses clause consists of the word uses, followed by a comma-separated list of module names, which is terminated by a semicolon. The modules listed in the clause have to be capable of exporting identifiers, that means a program name may not appear in the list. Usually unit names are listed in the clause. The module name of the module, that is about to be defined, can not appear in the list. Example:

	math, sysUtils, baseUnix;

access and shadowing

This makes identifiers exported by the listed modules, for units that means identifiers declared in the interface section, known in the current module. Either the fully-qualified identifier which is prefixed by the module name, and just the identifier’s stem can be used to refer to the same identifier. For instance, math.ceil as well as just ceil refer to the same function.

However, two or more units listed in the uses clause might declare the same identifier. Then, only the identifier declared by the unit later in the list can be referred to using the short notation. Identifiers declared by earlier units in the uses clause can only accessed be via fully-qualified identifiers. A with-clause may alleviate this situation.

automatic set-up

At program start, all initialization statement blocks, if any, are processed in the order the units were listed in – possibly recursively. At program termination, all finalization are processed in the reverse order.

If initialization fails, only units that have been initialized so far are finalized. The main block of a program is not executed at all.

special units

In FPC the unit system is implicitly included by every program. It is wrong to explicitly list it in the uses clause. Inclusion of the system unit can be disabled by using the -Us compiler switch. This switch indicates/ought to indicate, that a/the system unit is about to be compiled.

see also