same name, the compiler uses the one from the unit listed last in the uses clause. (To access the identifier from the
other unit, you would have to add a qualifier:
UnitName.Identifier
.)
A uses clause need include only units used directly by the program or unit in which the clause appears. That is, if
unit A references constants, types, variables, procedures, or functions that are declared in unit B, then A must use
B explicitly. If B in turn references identifiers from unit C, then A is indirectly dependent on C; in this case, C needn't
be included in a uses clause in A, but the compiler must still be able to find both B and C in order to process A.
The following example illustrates indirect dependency.
program Prog;
uses Unit2;
const a = b;
// ...
unit Unit2;
interface
uses Unit1;
const b = c;
// ...
unit Unit1;
interface
const c = 1;
// ...
In this example,
Prog
depends directly on
Unit2
, which depends directly on
Unit1
. Hence
Prog
is indirectly
dependent on
Unit1
. Because
Unit1
does not appear in
Prog
's
uses clause, identifiers declared in
Unit1
are
not available to
Prog
.
To compile a client module, the compiler needs to locate all units that the client depends on, directly or indirectly.
Unless the source code for these units has changed, however, the compiler needs only their .dcu (Win32) or .dcuil
(.NET) files, not their source (.pas) files.
When a change is made in the interface section of a unit, other units that depend on the change must be recompiled.
But when changes are made only in the implementation or other sections of a unit, dependent units don't have to
be recompiled. The compiler tracks these dependencies automatically and recompiles units only when necessary.
Dostları ilə paylaş: