[fpc-pascal] unit export control

spir ☣ denis.spir at gmail.com
Mon May 31 16:16:50 CEST 2010


I'm converting a few components, first developped in independant programs, into units. I have 2 issues in the process.

-1- internal dependency
How can an interface element E0 depend on an implementation element E1? I cannot find a way to "forward-declare" E1, before E0, and have its actual description in implementation. Anyway, forward-declaration is not possible for any type (cannot find how to do it for an enum or record)? And what about consts, vars, funcs or procs?
In my case, E0 & E1 are both class types; and E0 uses E1 as parameter type for some of its methods.

-2- namespace export
I would like, for some units, to export a single element, namely a namespace that holds as elements the actual elements of the unit to be exported. I guess you understand the purpose is to reproduce an import/export scheme common in some languages: namely that the importing unit can only refer to imported elements using "qualified names" such as "unit.element". This point is good, in my opinion, both for code clarity and for prevention of namespace pollution.
It seems a possibility to do that in pascal is to define everything in the implementation part, except for a single variable of a record type, used as a namespace. Then populate this variable in the initialization section. An issue is, again, that the namespace variable's own type certainly needs to be declared in the interface part.
Are there better ways to achieve this goal?

OT detail: Seems I cannot use named types for open array parameters. For instance
    procedure (structs : array of Struct);
is accepted, but the following not
    type StructArray = array of Struct;
    procedure (structs : StructArray);

Finally: I found online some very good introductions to Delphi. Can I rely on the information there to apply to freepascal (I mean in 99% cases)? For instance, the first point I met is a literal notation for records "r := (a:1 ; b:2);". But fpc refuses that to me :-( (Same result with array notations.)


vit esse estrany ☣


More information about the fpc-pascal mailing list