Multi-unit Namespaces
Multiple units can be grouped together into one namespace using an extension of the in clause in the project source
file. The file name string can list multiple unit source files in a semicolon-delimited list.
uses
MyProgram.MyNamespace in 'filepath/unit1.pas;otherpath/unit2.pas';
In this example, the namespace
MyProgram.MyNamespace
logically contains all the interface symbols from
unit1
and
unit2
.
Symbol names in a namespace must be unique, across all units in the namespace. In the example above, if
unit1
and
unit2
both define a global interface symbol named
mySymbol
, the compiler will report an error in the
uses clause.
You use a multi-unit namespace by specifying the namespace in the uses clause of a source file. Source code that
uses a multi-unit namespace implicitly uses all the units listed as being members of that namespace.
All the units defined by the current project as members of that namespace will be available to the compiler for symbol
lookup while compiling that source file.
The individual units aggregated in a namespace are not available to source code unless the individual units are
explicitly used in the file's uses clause. In other words, if a source file uses only the namespace, then fully qualified
identifier expressions referring to a symbol in a unit in that namespace must use the namespace name, not the actual
unit that defines that symbol.
A uses clause may refer to a namespace as well as individual units within that namespace. In this case, a fully
qualified expression referring to a symbol from a specific unit listed in the uses clause may be referred to using the
actual unit name or the namespace for the qualifier. The two forms of reference are identical and refer to the same
symbol.
23
Note:
Since unit identifiers are not emitted to .NET assembly metadata, explicitly using the unit in the uses clause
will only work when you are compiling from source or dcu files. If the namespace units are compiled into an
assembly and the assembly is referenced by the project instead of the individual units, then the source code
that explicitly refers to a unit in the namespace will fail because that unit name does not exist in the metadata
of the assembly.
24
|