Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Other Compiler    [ Add a report in this area ]  
Report #:  128737   Status: Open
Delphi namespaces is totally unusable feature.
Project:  Delphi Build #:  21.0.17017.3725
Version:    21.0 Submitted By:   Alexey Kazantsev
Report Type:  Feature Specification issue Date Reported:  11/6/2014 6:03:20 AM
Severity:    Extreme corner case Last Updated: 4/1/2015 1:41:38 AM
Platform:    All versions Internal Tracking #:   58727
Resolution: Retest (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (2 Total Ratings)
5.00 out of 5
Total Votes: 23
Description
From Delphi 2006 or earlier we can use namespaces with unit names.
Theoretically. Practically we cannot use them, because they not work. Totally.
Steps to Reproduce:
--------
program namespace_identifiers_using_bug;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  SomeNamespace.UnitName,
  SomeNamespace.OtherUnitName;

  // According to documentation for namespaces (http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/usingnamespaces_xml.html):
  //------------------------------------------
  // Multiple units can belong to the same namespace, if the unit declarations refer to the same namespace. For example, one can create two files, unit1.pas and unit2.pas, with the following unit declarations:
  //
  // // in file 'unit1.pas'
  // unit MyCompany.ProjectX.ProgramY.Unit1
  //
  // // in file 'unit2.pas'
  // unit MyCompany.ProjectX.ProgramY.Unit2
  // In this example, the namespace MyCompany.ProjectX.ProgramY logically contains all of the interface symbols from unit1.pas and unit2.pas.
  //------------------------------------------
  // We can drop unit name when using identifiers with namespace. But it not work.

Var

// Delphi 2006 - fail
// Delphi 2007 - fail
// Delphi 2009 .. XE7 - OK
c    : SomeNamespace.TMyClass;
rec  : SomeNamespace.TMyRecord;
oc   : SomeNamespace.TOtherMyClass;
orec : SomeNamespace.TOtherMyRecord;

// And what is more:

d    : SomeNamespace.Data; // OK

// Declared identifier can override identifier in namespace
data : SomeNamespace.Data; // fail

begin

// Delphi 2006 .. XE7 - fail
c  := SomeNamespace.TMyClass.Create;
oc := SomeNamespace.TOtherMyClass.Create;

// Delphi 2006 - XE7 - fail
SomeNamespace.MyProc;
SomeNamespace.OtherMyProc;

end.
--------
Workarounds
None
Attachment
delphi_namespaces.zip
Comments

Tomohiro Takahashi at 3/19/2015 7:41:45 PM -
This is a comment from internal tracking system.
<<<<
As you can read from doc.
http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/usingnamespaces_xml.html

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.

For example:

  SomeNamespace.UnitName.TMyClass;

In this case we just remove identifier and dot from right side and namespase would be SomeNamespace.UnitName.
The dot in the middle of the name is not a divider of namespace.
>>>>

Alexey Kazantsev at 3/29/2015 12:56:16 AM -
You must reopen this report because current behavior absolutely contradict of documentations:

(http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/usingnamespaces_xml.html):
  //------------------------------------------
  // Multiple units can belong to the same namespace, if the unit declarations refer to the same namespace. For example, one can create two files, unit1.pas and unit2.pas, with the following unit declarations:
  //
  // // in file 'unit1.pas'
  // unit MyCompany.ProjectX.ProgramY.Unit1
  //
  // // in file 'unit2.pas'
  // unit MyCompany.ProjectX.ProgramY.Unit2
  // In this example, the namespace MyCompany.ProjectX.ProgramY logically contains all of the interface symbols from unit1.pas and unit2.pas.
  //------------------------------------------

According this quotation in my example all symbols from "UnitName" and "OtherUnitName" must be accessible in namespace "SomeNamespace". And currently it works in declaration but not in using.

Mykhaylo Skachkov at 4/20/2015 6:14:06 AM -
i would like to add my notes to this issue:

according to documentation
(http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/usingnamespaces_xml.html)

there are two places that say opposite things:

1) 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 just the name of the unit that defines that symbol.

2) 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 fully-qualified name (including namespace and unit name) for the qualifier. The two forms of reference are identical and refer to the same symbol.


so the item (1) says that if you declared units

Company.Project.Area.Unit1;
and
Company.Project.Area.Unit2;

then in source code if you put

uses Company.Project.Area;

then you then must use

Company.Project.Area.Unit1.MySymbol1

reference to use MySymbol1 symbol.

however the item (2) it says that you can use

Unit1.MySymbol1 reference AND Company.Project.Area.Unit1.MySymbol1


so there are some conclusions there:
a). you cannot put
uses Company.Project.Area;
to your uses clause because compiler expects it to find Company.Project.Area.pas file there. this is definitely a BUG that breaks basic functionality

b) [if (a) is fixed] documentation says opposite things about whether it allows to use Unit1.MySymbol1 instead of fully-qualified name (Company.Project.Area.Unit1.MySymbol1). if only fully-qualified way would be allowed then it makes using namespaces useless.

Mykhaylo Skachkov at 4/20/2015 6:16:39 AM -
*the basic functionality does not work on XE7 (21.0.17017.3725)

Server Response from: ETNACODE01