Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-05

unit export control

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

spir ☣

Hello,

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

Denis
________________________________

vit esse estrany ☣

spir.wikidot.com

Reply by email

Jonas Maebe
to spir ☣
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?

No.

Show quoted text 5 lines
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.

Jonas

Reply by email

Luca Olivetti
to Jonas Maebe

Al 31/05/10 18:25, En/na Jonas Maebe ha escrit:

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

It works with typed constants

Bye

Luca

Reply by email