[fpc-devel] Namespaces like URLs

Adem listmember at letterboxes.org
Tue Jul 27 03:48:41 CEST 2010


  On 2010-07-27 4:14 AM, Martin wrote:
>> And, it seem you did not read the rest of my post (including the 
>> first one with this subject line) :)
> Yes.
>
> I am with Graeme on this one, as in I do not see what you may have 
> written, that solved the above....
>
> To be sure: this mail ?:  
> http://lists.freepascal.org/lists/fpc-devel/2010-July/021112.html
>
> where does it solve that if I write a unit with this lazarus namespace 
> (my installation)
> C:\laz_svn\
Let's call that a local URL/URI.

You would make a not of that in a cfg file --either a global one, or per 
project.
> will work on a default windows install; not to speak a linux system. 
> The path depends on the system.
Yes. And, as long as you're working on it on a single machine and not 
intending to move to another machine, that solution is fine.

But, if any of the above is changed, you would have to setup an exactly 
the same folder structure elsewhere.
> If you mean the path, is only a string or placeholder, and does not 
> actually point to the sources (which I can not find in your mail), 
> then how does fpc know the correct path to the source? (I have 4 
> lazarus instalations, and 3 fpc installations => with different 
> versions => how is fpc going to work that out? 
Let's consider a case that is complex yet simple enough to be generalized.

Suppose I have my copy of Lazarus on a different machine (a NAS server) 
on the local network.

Here is the Samba path to it: '//NAS_Box/Development/SVN/Lazarus/'

IOW, for this local network, this is the URL to 'Lazarus' sources. Lets 
call it 'lazarus_svn'

Now, suppose I need to access and use the file called 'frFuncNum.pas'

 From 'lazarus_svn' this is its' path: 
'trunk/components/lazreport/source/addons/addfunction'

Or, in 'namespace' parlance, [please ignore the symbols]

lazarus_svn.trunk.components.lazreport.source.addons.addfunction.frfuncnum.pas

Fine. Now, have path to that file that is unmistakeable.

Up to this point, we have nothing to do with 'alias'es.

Aliases come into play only when we need to refer to something in 
'frfuncnum.pas' that might conflict with another on in the 'uses' clause.

Here is what I mean:

Say, you have a function called 'frIsRangeNum' in one of YOUR units 
which also exists in 'frfuncnum.pas'.

To make sure you're referring to the correct one, you would (otherwise) 
have to write the following (on a single line, every time)

Result := 
lazarus_svn.trunk.components.lazreport.source.addons.addfunction.frfuncnum.frIsRangeNum();

As we all agree, that's inhumane.

So, you could use an alias for 
'lazarus_svn.trunk.components.lazreport.source.addons.addfunction.frfuncnum.pas' 
and call it, say, 'Laz_svn'.

Once you do that, the above long line becomes such --which is a lot more 
manageable.

Result := Laz_svn.frIsRangeNum();

Obviously, instead of using 'namespace', you could go straight on and 
declare the alias as an absolute path to the actual file, but, that 
would make that code totally unportable.

Side note: As you probably know; Delphi, too, uses a kind of URL. If you 
look under 'Options' you could see stuff like '$(BDSCOMMONDIR)' or 
'$(BDS)' etc. And, you can also declare your own, such as '$VCL' to 
point to your own directory called 
'C:\Users\username\AppData\Local\VCL'. Trouble is, they are not 
definable per project nor are they easily transferable from machine to 
machine.



More information about the fpc-devel mailing list