How can you declare mutually dependent object datatypes?

I want to have two object types that refer to each other in their definitions, but I can't get it to compile.

For example, how can I make the following work:

---

type Tfoo = class
      procedure munge(bar : tBar);
   end;

type Tbar = class
      procedure munge(foo : tFoo);
   end;

---

Many thanks,


Rich
ricbradAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Lee_NoverConnect With a Mentor Commented:
type
  TBar = class; // this is a forward declaration - note that all classes must be declared in the same 'type' 'group'
  Tfoo = class
      procedure munge(bar : tBar);
   end;

  Tbar = class
      procedure munge(foo : tFoo);
   end;
0
 
Ivanov_GCommented:
Lee_Nover, your example will work just for class members...
  TBar = class;

  TFoo = class
    member : TBar;
  end;

  TBar = class
    member : TFoo;
  end;
0
 
Ivanov_GCommented:
sorry, my mistake... I made something wrong... :)
0
 
Wim ten BrinkSelf-employed developerCommented:
LOL@Ivanov_G
That's what we call a moment of total blindness... :-P Don't worry, none of us are perfect, not even me...
0
All Courses

From novice to tech pro — start learning today.