Hi
I have a class called A and a class called B, within the same unit
how can I put pointers to them within each other?
for example:
Type
a = class
pointerB: B;
end;
Type
b = class
pointerA: A;
end;
because I need that type A to have a parent, and the parent would be B, but A is a child of B, so A is declared in B as well...
how?
thanks
Comments
:
: I have a class called A and a class called B, within the same unit
:
: how can I put pointers to them within each other?
:
: for example:
:
: Type
: a = class
: pointerB: B;
: end;
:
: Type
: b = class
: pointerA: A;
: end;
:
: because I need that type A to have a parent, and the parent would be
: B, but A is a child of B, so A is declared in B as well...
: how?
:
: thanks
:
You can forward-declare a class name as long as the class is defined within the same type-declaration:
[code]
type
TB = class; // Declare TB as a name for a class
TA = class(TObject)
private
FB: TB;
public
property B: TB read FB;
end;
TB = class(TObject) // Declaration of TB
private
FA: TA;
public
property A: TA read FA write FA;
end;
[/code]
: TB = class; // Declare TB as a name for a class
:
: TA = class(TObject)
: private
: FB: TB;
: public
: property B: TB read FB;
: end;
:
: TB = class(TObject) // Declaration of TB
: private
: FA: TA;
: public
: property A: TA read FA write FA;
: end;
: [/code]:
thanks, it worked