Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Chicken and Egg with declarations

Status
Not open for further replies.

enonod

Programmer
Jan 7, 2005
22
GB
I have an object that produces two of it's own kind on prompt.
The method that does this is a function that must return them.
Function can only return one item, so I decided on an array to do it.
The only way I could see was to declare the array type first and then use it as the return type but the chicken and egg problem arose.

Type
TItemArray=array[1..2] of TBalloon;

TBalloon=Class(TObject)
Private
;
public
function TBalloon.MakeTwoMore(Avalue: integer): TItemArray;

implementation
function TBalloon.MakeTwoMore(AValue: Integer): TItemArray;
begin
result[1]:=TBalloon.create(5);
result[2]:=TBalloon.create(9);
end;


Of course, TItemArray knows nothing of TBalloon, not yet declared.
If I Place TItemArray declaration after TBalloon declaration then the function knows nothing of TItemArray.

Can somebody please point me in the right direction.
Regards
 
This is what you should do:
Code:
Type 
    TBalloon=Class;     // This is a forward definition

    TItemArray=array[1..2] of TBalloon;

    TBalloon=Class(TObject)
    Private
    ;
    public
        function TBalloon.MakeTwoMore(Avalue: integer): TItemArray;
  .....


Andrew
Hampshire, UK
 
Thank you Andrew
It always seems so obvious AFTER somebody answers it, but it is part of the learning process I guess.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top