[fpc-devel] Namespaces [was: is that intended? private type section in classes versus visibility]
graemeg.lists at gmail.com
Mon Jul 26 10:22:47 CEST 2010
Op 2010-07-26 02:45, Hans-Peter Diettrich het geskryf:
> How should that work? How to distinguish between <std>utils.pas and
> <other>utils.pas, in "using utils;"?
I'm thinking in the line of working with something like Lazarus Packages.
This is not limited to Lazarus only though. When I talk about a "lazarus
package" I mean a set of code (units) that act as one "library" in a sense.
Lets use a Lazarus Package (*.lpk) as a simple example.
We have a lazarus package named: fpgui_toolkit.lpk
Compile that package with '-namespace=fpgui' and all compiled units are
output to a 'lib' directory.
Now we have a project that uses that Lazarus Package as a dependency,
referencing the already compiled units directory 'lib' from the
fpgui_toolkit.lpk package (this means compiling this project doesn't need
to compile the fpGUI toolkit units - they are already compiled). Now lets
say this project also contains a utils.pas (fpgui_toolkit.lpk also
contained a utils.pas unit). Now if this project wants to reference the
utils.pas from fpGUI package, it would use the <namespace>.<unitname>
format in the uses clause. If this project only used 'uses utils;' then it
would reference the utils.pas of this project (part of the "global"
namespace which takes priority" because this project was not compiled with
a -namespace= parameter.) and not of the utils.pas in the fpgui_toolkit
utils, // utils.pas from this project - part of "global" namespace
fpgui.utils, // utils.pas from "fpgui" namespace
No if our current project didn't contain a utils.pas unit, then we could
simply reference the utils.pas from fpGUI package without the need for the
utils, // only utils.pas the compiler knows about (based on
// search/library paths is the one in "fpgui" namespace.
See, no need for a global system wide cache like .NET Simply use the search
and library paths passed to the compiler. 3rd Party code (like the
fpgui_toolkit.lpk package) must be compiled separately if you want them to
have a different namespace from the current project. Alternatively, all
units must define the namespace they belong to, inside the unit on the
'unit' line. Then you don't need to pre-compile 3rd party units.
unit fpg_button namespace fpgui;
- Graeme -
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
More information about the fpc-devel