Solved

How can you declare mutually dependent object datatypes?

Posted on 2004-09-03
4
176 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now