Circular Unit References
When units reference each other directly or indirectly, the units are said to be mutually dependent. Mutual
dependencies are allowed as long as there are no circular paths connecting the uses clause of one interface section
to the uses clause of another. In other words, starting from the interface section of a unit, it must never be possible
to return to that unit by following references through interface sections of other units. For a pattern of mutual
dependencies to be valid, each circular reference path must lead through the uses clause of at least one
implementation section.
In the simplest case of two mutually dependent units, this means that the units cannot list each other in their interface
uses clauses. So the following example leads to a compilation error:
unit Unit1;
interface
uses Unit2;
// ...
unit Unit2;
interface
18
uses Unit1;
// ...
However, the two units can legally reference each other if one of the references is moved to the implementation
section:
unit Unit1;
interface
uses Unit2;
// ...
unit Unit2;
interface
//...
implementation
uses Unit1;
// ...
To reduce the chance of circular references, it's a good idea to list units in the implementation uses clause whenever
possible. Only when identifiers from another unit are used in the interface section is it necessary to list that unit in
the interface uses clause.
19
|