Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • 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 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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