[Lazarus] Circular references

Martin lazarus at mfriebe.de
Fri Aug 14 10:54:06 CEST 2009


Michael Van Canneyt wrote:
> On Fri, 14 Aug 2009, Graeme Geldenhuys wrote:
>> Michael Van Canneyt wrote:
>>> This is the world upside down.
>> So why is forward declarations allowed? It's the same principle!
> No, because the declaration is guaranteed to follow in the same unit.
> A unit forms a self-contained whole.
>
> Unit loading is a difficult matter as it is. If you start spreading 
> declaration and implementation over different units, I'm not sure that
> the compiler can guarantee correctness.
>
> But Florian should answer this, he is more knowledgeable about the
> compiler internals.
Actually, I think the current design is right.

the gains of a "class declared external" are far less than thought.

A class of which the details where only known in the implementation, may 
be allowed to be referred in the interface. But otherwise it would be 
like any other class that was declare in implemantation: a type local to 
this unit.

That is, if a unit with that trick, did try to use this forwarded 
declaration in any public section, or anywhere where it was accessible 
by units using this unit, then the problems would start.

Because if I am using unit XYZ, and access the public property or method 
ABC that refers to some class, then add this time this some class *must* 
be fully known (or the compiler will have to go into all kind of extra 
checks and whatever else).
If  it was on public methods properties how would the compiler know that 
outside units are supplying the correct type? Only by reading the 
implementation, and then you will need multipass compiling....

So that a class can only be used for private stuff on this class. it can 
no be used for the customer/order relations, as they would require this 
internal class, on public methods/properties.

My 2 cents

Martin








More information about the Lazarus mailing list