Solved

How can you declare mutually dependent object datatypes?

Posted on 2004-09-03
4
179 Views
Last Modified: 2011-04-14
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
Comment
Question by:ricbrad
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 75 total points
ID: 11971275
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
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11971342
Lee_Nover, your example will work just for class members...
  TBar = class;

  TFoo = class
    member : TBar;
  end;

  TBar = class
    member : TFoo;
  end;
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11971353
sorry, my mistake... I made something wrong... :)
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11971989
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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question