how to make classes that are referencing circular?
Posted on 2003-12-02
is there a way to let container classes have a reference to their "childclasses" (the object they are containing)
and these objects have a pointer to their container.
im just making a set of components for our own sprite class.
these components should all be in a Controlpanel that is only a
container for the things that can be shown in it.
so the controlpanel knows all objects that can be shown in it.
for easier use it would be nice to only set the properties of the
controlpanel and all other objects can access these properties.
because of that i want to give the objects a parent property.
and so i have a circle.
TControlpanel = class(TObject)
TControlpanelObject = class(TObject)
as you can see this code will not compile.
the units will get quite big so i want to put classes in different units (to be exact there will be
more than one unit with controlpanel objects for instance: feedback)
forward declarations work only in the same unit?
i know that i can use the unit1 in the implementation part of the unit 2 and can typecast the
parentcontainer but i hoped that there is a nicer solution.
i also know that i could put all classes in the same unit
but i dont like units that have much more than 1000 lines