[Lazarus] Circular references
Lance Collins
collinsl at bigpond.net.au
Fri Aug 14 05:48:43 CEST 2009
Sorry if this is the wrong place to discuss language issues.
I saw the following on the ADUG Delphi list and wondered if there was
a possible Lazarus feature here.
Cheers
Lance
------------------------------------------------------------------------------------------------
> How can you avoid circular references with two modules that
> interact with each other?
This has been discussed before in the Delphi newsgroups and it has been
requested of BIBCE (Borland/Inprise/Borland/CodeGear/E9o) several times.
IIRC there may be a QC entry.
Basically it should be possible with a minor language change and not too
much effort from the compiler team. Something like:
unit ParentObject;
interface
TChild = forward class; // My made-up syntax
// or TChild = implementation class; or some other syntax!
TParent = Class
public
property Child :TChild;
end;
implementation
uses ChildObject;
// Nothing special here, only need the love one-way
// but you could do it both ways if you want
unit ChildObject;
interface
uses ParentObject;
TChild = Class
public
property Parent :TParent;
end;
"TChild = forward class" tells the compiler that TChild is a class, and the
complete type information is known in the implementation section (which the
compiler can validate). That's all the compiler needs to know in the
interface section - essentially it needs to know the kind and size of the
type. It doesn't require a two-pass compiler or any other extreme make-over.
This feature is often needed and the "if you need to do that then something
is wrong with your design" argument doesn't fly with me. It's one of the C++
features that I wish Delphi had. I'm holding out for D2011 - perhaps the new
compiler will have it!
More information about the Lazarus
mailing list