Fully qualified unit names

The following example demonstrates the uses clause with namespaces:

unit MyCompany.Libs.MyUnitl uses MyCompany.Libs.Unit2, // Fully qualified name. UnitX; // Generic name.

Once a module has been brought into context, source code can refer to identifiers within that module either by the unqualified name, or by the fully qualified name (if necessary, to disambiguate identifiers with the same name in different units). The following writeln statements are equivalent:

uses MyCompany.Libs.Unit2; begin writeln(MyCompany.Libs.Unit2.SomeString); writeln(SomeString); end.

A fully qualified identifier must include the full namespace specification. In the preceding example, it would be an error to refer to SomeString using only a portion of the namespace:

writeln(Unit2.SomeString); // ERROR!

writeln(Libs.Unit2.SomeString); // ERROR!

writeln(MyCompany.Libs.Unit2.SomeString); // Correct.

writeln(SomeString); // Correct.

It is also an error to refer to only a portion of a namespace in the uses clause. There is no mechanism to import all units and symbols in a namespace. The following code does not import all units and symbols in the MyCompany namespace:

uses MyCompany; // ERROR!

This restriction also applies to the with-do statement. The following will produce a compiler error:

with MyCompany.Libs do // ERROR!

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment