I'm also posting this message on the beginners messageboard, though I'm already quite familiar with Delphi. However, the problem described below might be a beginner's problem.
I have a problem writing OO-code in Delphi. How can I use classes which are defined later in the code? Here is an example, what my problem looks like (abstract example):
TObj1 = class
field : TObj2;
end;
TObj2 = class
field : TObj1;
end;
As you can see, changing the order of the declaration will not solve the problem. I was used from writing OO-code in Pascal, that you (normaly) use pointers to objects instead of object vars:
{pascal code}
PObj1 = ^TObj1;
PObj2 = ^TObj2;
TObj1 = object
field : PObj2;
end;
TObj2 = object
field : PObj1;
end;
But since Delphi replaces the need to use pointers to objects simply by using classes (as I mentioned in Delphi, var a : TObject; is actually a pointer to an instance of (an inheritor of) TObject), this doesn't look to be the right way.
Please help me - is there any possibility to declare classes "forward"? Or any other way to do this?
Thank you.
Comments
:
: TObj1 = class
: field : TObj2;
: end;
:
: TObj2 = class
: field : TObj1;
: end;
:
: But since Delphi replaces the need to use pointers to objects simply by using classes (as I mentioned in Delphi, var a : TObject; is actually a pointer to an instance of (an inheritor of) TObject), this doesn't look to be the right way.
:
: Please help me - is there any possibility to declare classes "forward"? Or any other way to do this?
:
: Thank you.
:
Hi there, you can make a forward class declaration.
[code]
Type
TObj2 = class; // Forward declaration of TObj2
TObj1 = class
field : TObj2;
end;
TObj2 = class
field : TObj1;
end;
[/code]
HTH
Richard