Forward defined types (and object references)
Peter N Lewis
peter at stairways.com.au
Wed Jul 6 09:51:43 CEST 2005
At 9:07 +0200 6/7/05, Marco van de Voort wrote:
> > marcov at stack.nl wrote:
>> > Delphi supports this: (remember its object model is similar)
>> > Type
> > > MyObjectB = class;
> > > MyObjectA = class;
>> This seems to be what `class .. end' is in OOE.
>> > Must be in one typeblock though, IOW, the same system as pointers.
>> Yes, same in OOE.
>Does CW work like OOE in this regard?
No, CW does not accept either syntax:
MyObject = object;
MyObject = object .. end;
CW takes the approach that any unknown type identifier it sees in a
type definition is pointer sized (a pointer or object) and must be
defined by the end of the type block.
rec = record
UndefinedA = ^Integer;
UndefinedB = object
Note that UndefinedA = UInt32 is not legal, it must be a pointer or object.
It's actually not a bad methodology and makes it easy to write data
structures that is self or mutually referential, but it does not add
anything over pre defining pointers or object names as EP/Delphi.
>Note that afaik there is no solution for BP style objects, and actually you
>don't really need it, since in practice you always work with references
There is still this case:
proc = procedure ( var o: MyObject );
MyObject = object
But I agree, in practice with non-reference objects, the issue is a
lot less prevalent.
More information about the Gpc