Re:Circular unit reference - how to solve
Quote
dmurd...@mast.queensu.ca (Duncan Murdoch) writes:
>In article <johnsylv.5.00138...@InterLink.Net> johns...@InterLink.Net (John Sylvestre) writes:
Thanks for all responses on my question.
Quote
>>To avoid the circular reference problem;
>>Place the first use clause in the interface part of Unit A ...
>>In unit B place the use clause for unitA in the implementation part.
>This doesn't work, because unitA is needed in the interface to unitB in order
>to resolve the meaning of a TClassA typed field declared there. (I deleted
>this in the extract I quoted above.) Someone else worked around this by
>changing one of the type declarations to an untyped pointer and then
>typecasting it, and another solution was to declare an ancestor type somewhere
>else and have each unit use that instead.
This is correct. It wouldn't work for me to move the unit declaration to the
implementaion part of unit b. The pointer soultion would work but
it would make the code look more hard to read and manage, it would be a
last resort for me.
Quote
>I still think the best solution is to put both classes in the same unit,
>possibly in separate include files. These two classes must be intimately
>related if they use each other so closely, so it makes sense for them to be
>logically grouped together.
Yes, they are intimately related but I would have liked to have them in two
separate units, but it doesn't look like it can be made. I think I will go for
joining the two classes in one file or make two separate include files.
Quote
>A valid reason to employ one of these kludges to get them into separate units
>would be if the implementations involved so much code that it wouldn't all fit
>into one unit. In that case, it would probably make sense to have multiple
>types in a hierarchy anyways; I don't think I've ever needed 64K of code to
>implement just two object types.
The classes are not that huge, but I like the concept of having one class in
one unit. In this case it doesn't seams like it's possible.
/Ulf Mansson
--
Ulf Mansson, Systems Management at Chalmers Univ. of Technology
ma...@mot.chalmers.se Ph: +46 31 7725280, 7722497(fax)
Snail: Chalmers Univ. of Tech., S-412 96 Goteborg, Sweden