Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TCollectionItem with a TCollection member???

Status
Not open for further replies.

rcloutie

Programmer
May 26, 2005
164
CA
Hi there,

First, I'm using Delphi 2006.

I've defined 3 classes to implement collection minding in my app.
TclsArtItem = class(TCollectionItem)
TclsArtList = class(TCollection)
TclsArt = class(TCollection)

All works fine but one thing: TCollectionItem must have a member which is of type TCollection. Yes, a recursive architecture...

Here's an example in the real life: a product is built from some products (components) and take part of some other products which in turn can be component of others products...

So, how to create a property in the TCollectionItem class which refers to the TCollection?

Thanks for help,

RC
 
Delphi allows forward declarations. You can do this as follows:
Code:
[navy][i]// for automatic syntax highlighting see faq102-6487 
[/i][/navy][b]unit[/b] MyUnit;

[b]interface[/b]

[b]type[/b]
  TclsArtList = [b]class[/b](TCollection);

  TclsArtItem = [b]class[/b](TCollectionItem)
  [b]private[/b]
    FCollection: TclsArtList;
  [b]end[/b];

  TclsArtList = [b]class[/b](TCollection)
  [b]private[/b]
  [navy][i]// put the class stuff here 
[/i][/navy]  [b]end[/b];
 
oops. Change the forward declaration to
Code:
  TclsArtList = class;
[code]

At least that's what I have in my progs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top