[fpc-pascal] Migrating MW objects definitions

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Oct 6 15:01:56 CEST 2005


On 6 okt 2005, at 14:40, fpanasiti at tiscali.it wrote:

> I'm trying to migrate MW OO code to FPC. I'm in trouble with this  
> piece of
> MW code:
>
> type
> myObjectA = object
> .....
> lObj: myObjectB;
> ...
> end;
>
> type
> myObjectB = object
> ...
> lObj: myObjectA
> ...
> end;
>
> Essentially when the compiler tries to deal with myObjectA, it says  
> that
> 'myObjectB is not defined'.
>
> Am I doing something wrong, or is it something not supported by FPC?

You have to use a forward declaration:

type
   MyObjectB = object;

   myObjectA = object
     .....
     lObj: myObjectB;
     ...
   end;

   myObjectB = object
     ...
     lObj: myObjectA
     ...
   end;

Notes:

a) forward declaration of MacPascal-style objects was not supported  
in our initial implementation due to a bug
b) the forward declaration and the full declaration of a type must be  
present in the same type-block (which is not the case in your example  
above, even if you would add a forward declaration, since there you  
start a new type-block for each declaration)


Jonas



More information about the fpc-pascal mailing list