[fpc-pascal] unit export control

Jonas Maebe jonas.maebe at elis.ugent.be
Mon May 31 18:25:13 CEST 2010

On 31 May 2010, at 16:16, spir ☣ wrote:

> 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?

It cannot, regardless of the nature of E0 and E1.

> -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);

These are two different things. The first is an "open array" and the second is a "dynamic array". You may want to look these terms up in the documentation.

> 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)?

a) it depends on which Delphi version the introduction uses. Generally, FPC supports most things from Delphi 7 and earlier.
b) make sure you use {$mode delphi} if you want to use code written for Delphi.

> 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.)

FPC indeed does not support this, and I'm not aware of any immediate plans to add support for this.


More information about the fpc-pascal mailing list