Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

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
0
ricbrad
Asked:
ricbrad
  • 2
1 Solution
 
Lee_NoverCommented:
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 BrinkCommented:
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now