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



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

Declaring Namespaces
In Delphi 2005, a project file (program, library, or package) implicitly introduces its own namespace, called the project
default namespace. A unit may be a member of the project default namespace, or it may explicitly declare itself to
be a member of a different namespace. In either case, a unit declares its namespace membership in its unit header.
For example, consider the following explicit namespace declaration:
unit MyCompany.MyWidgets.MyUnit;
First, notice that namespaces are separated by dots. Namespaces do not introduce new symbols for the identifiers
between the dots; the dots are part of the unit name. The source file name for this example is
MyCompany.MyWidgets.MyUnit.pas, and the compiled output file name is MyCompany.MyWidgets.MyUnit.dcuil.
Second, notice that the dots imply the conceptual nesting, or containment, of one namespace within another. The
example above declares the unit 
MyUnit
 to be a member of the 
MyWidgets
 namespace, which itself is contained
in the 
MyCompany
 namespace. Again, it should be noted that this containment is for documentation purposes only.
A project default namespace declares a namespace for all of the units in the project. Consider the following
declarations:
Program MyCompany.Programs.MyProgram;
Library MyCompany.Libs.MyLibrary;
Package MyCompany.Packages.MyPackage;
These statements establish the project default namespace for the program, library, and package, respectively. The
namespace is determined by removing the rightmost identifier (and dot) from the declaration.
A unit that omits an explicit namespace is called a generic unit. A generic unit automatically becomes a member of
the project default namespace. Given the preceding program declaration, the following unit declaration would cause
the compiler to treat 
MyUnit
 as a member of the 
MyCompany.Programs
 namespace.
20


unit MyUnit;
The project default namespace does not affect the name of the Delphi source file for a generic unit. In the preceding
example, the Delphi source file name would be MyUnit.pas. The compiler does however prefix the dcuil file name
with the project default namespace. The resulting dcuil file in the current example would be MyCompany.Programs.
MyUnit.dcuil.
Namespace strings are not case-sensitive. The compiler considers two namespaces that differ only in case to be
equivalent. However, the compiler does preserve the case of a namespace, and will use the preserved casing in
output file names, error messages, and RTTI unit identifiers. RTTI for class and type names will include the full
namespace specification.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   29   30   31   32   33   34   35   36   ...   294




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

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin