Recent

Author Topic: Implementation of name spaces in FPC/Delphi  (Read 1387 times)

soerensen3

  • Full Member
  • ***
  • Posts: 213
Implementation of name spaces in FPC/Delphi
« on: January 17, 2020, 03:01:36 pm »
Am I right to assume that this is just a very complicated way of saying that with pascal namespaces a unit name can now contain dots?

Delphi: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/usingnamespaces_xml.html
Free Pascal: https://forum.lazarus.freepascal.org/index.php?topic=39937.0

I mean if I cannot do this
Code: Pascal  [Select][+][-]
  1. unit test.test1;
  2. ...
  3. type
  4.   TTest
  5.   end;
  6. ...
  7.  

Code: Pascal  [Select][+][-]
  1. unit test test2;
  2. ...
  3. type
  4.   TTest2 = class
  5.   end;
  6. ...
  7.  

Code: Pascal  [Select][+][-]
  1. project testproject;
  2.  
  3. uses test; //namespace
  4.  
  5. type
  6.   TTest3 = class( TTest )
  7.   end;
  8.  

So using the dotted notation is technically the same as eg. use a underscore?
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Implementation of name spaces in FPC/Delphi
« Reply #1 on: January 17, 2020, 03:21:00 pm »
Not quite.
Using your example:
Code: Pascal  [Select][+][-]
  1. unit test.test1;
  2. ...
  3. type
  4.   TTest = class
  5.   end;
  6. ...
// look here:
Code: Pascal  [Select][+][-]
  1. unit test2.test1;
  2. ...
  3. type
  4.   TTest = class
  5.   end;
  6. ...
  7.  
So:
Code: Pascal  [Select][+][-]
  1. project testproject;
  2.  
  3. uses test.test1; //namespace
  4.  
  5. type
  6.   TTest3 = class( TTest )
  7.   end;
You can also define the scope from the command line, in that case  uses test1 will suffice for both cases.
 


 
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Implementation of name spaces in FPC/Delphi
« Reply #2 on: January 17, 2020, 03:22:55 pm »
No, but the other part is FPC 3.2+.

So if you have say generics.collections and generics.defaults, declared with

Code: Pascal  [Select][+][-]
  1. unit generics.collections;
  2. interface
  3. ...
  4. etc

and compile a program with -FNgenerics then

both

Code: Pascal  [Select][+][-]
  1. uses generics.collections;

and

Code: Pascal  [Select][+][-]
  1. uses collections;

will work. Which doesn't work with underscores.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Implementation of name spaces in FPC/Delphi
« Reply #3 on: January 17, 2020, 03:43:53 pm »
@Marco
Thx for adding the command line parameter. Exactly what I mean.
Specialize a type, not a var.

soerensen3

  • Full Member
  • ***
  • Posts: 213
Re: Implementation of name spaces in FPC/Delphi
« Reply #4 on: January 17, 2020, 04:05:38 pm »
Ok now I get it. So my example of having types defined across different units in a common name space is not possible without forwarding the types in one common unit?
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Implementation of name spaces in FPC/Delphi
« Reply #5 on: January 17, 2020, 04:52:28 pm »
Ok now I get it. So my example of having types defined across different units in a common name space is not possible without forwarding the types in one common unit?

No. Units are already the leaf namespaces. The new functionality is just a mock hierarchy, not really new namespace functionality.

It was mainly meant for the VCL that uses some come names like "controls","forms" and "masks" and switch them between FMX and VCL.  So Delphi XE2 and later rename all units to VCL. and System. (for RTL units).

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Implementation of name spaces in FPC/Delphi
« Reply #6 on: January 17, 2020, 05:18:57 pm »
Point is: you can also use that functionality yourself if required.
Specialize a type, not a var.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Implementation of name spaces in FPC/Delphi
« Reply #7 on: January 17, 2020, 10:48:42 pm »
So how would I separate the difference between a name.space and a Name.AMember of the unit with the same name ?

 I see a condition where a non named space unit having a member of said secondary name and then a named.Spaced.AMember of the same name..

 Looks confusing to me.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018