Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework


Multiple and Indirect Unit References



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə30/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   26   27   28   29   30   31   32   33   ...   294
DelphiLanguageGuide

Multiple and Indirect Unit References
The order in which units appear in the uses clause determines the order of their initialization and affects the way
identifiers are located by the compiler. If two units declare a variable, constant, type, procedure, or function with the
17


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.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   26   27   28   29   30   31   32   33   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin