Hi everybody, here is a challenge for you!
There is a very important principle in Pascal:
Use units to structure the code.Let's assume you have a library which consists of many units (Base, BaseExt1, BaseExt2,...). Each unit contains one distinct class.
If I want to use this library I have to include all the units in the program file. It would be far more desirable to have just one "library unit" instead which also presents all the functionality of all the other units (their interface parts) to the program.
My first approach:unit1.pas
"forwards" all the functions of the other units.
E.g.
unit unit1;
...
unit2.myfunc: Integer;
...
But this is restricted to functions. Constants and records cannot be forwarded this way (if I remember correctly). Also this means you have to basicly write down the interfaces of all the other units in unit1 again. If you change something in one of these units, you have to update unit1, too. This is no clean way.
My second approach:Using namespaces: Since FPC 3.0.0 and Delphi 2009 (I guess?)
namespaces are supported in the form of
dotted units. My understanding was, that if I rename the units to e.g.:
libunit
libunit.base
libunit.ext1
libunit.ext2
...
it would be possible to just put libunit in the uses clause of the program file. This fails though. And on closer examination of the reference link given above, it doesn't seem to be made for that purpose.
Any hints on how to achieve to load all the units (of a library) by just calling the base library unit in the uses clause of the program?
Best regards
BC