Thanks Dennis and Phil. Your replies were very helpful - now to decide which way to go...

 

Cheers

Dave Jollie
Developer, TOWER NZ IT

(: 09 368 4259
Ê: 09 306 6801
*: [EMAIL PROTECTED]
.: 46 Parnell Rd, Parnell, Auckland

-----Original Message-----
From: Phil Middlemiss [mailto:[EMAIL PROTECTED]
Sent: Wednesday, 6 August 2003 8:44AM
To: Multiple recipients of list delphi
Subject: Re: [DUG]: Best methods for representing a 3 dimensional array

 

It really depends upon the architecture it is fitting into, and whether you are likely to want to reuse such a structure in other projects, or elsewhere in the same project. It would probably be worthwhile you doing as OO anyway just to get a bit of practice in.

 

I would use a base class that had all of the parent-child behaviour already implemented. For example:

 

// forward declare this so that we can declare the TParentChildClass;

TParentChild = class;

TParentChildClass = class of TParentChild;

 

// finish declaring this

TParentChild = class

private

  FOwner : TParentChild;

  FChildClass : TParentChildClass;

  FChildList : TList;

protected

  function GetChild(Index : Integer): TParentChild;

  Property ChildClass : TParentChildClass read FChildClass write FChildClass;

public

  function AddChild : TParentChild;

  procedure RemoveChild(Index : Integer; FreeChild : Boolean);

  function ChildCount : Integer;

  property Child[Index : Integer] : TParentChild read GetChild;

end;

 

This is just a rough outline really, you will want to add or change the functionality depending on what you want to acheive.

 

Phil.

----- Original Message -----

Sent: Wednesday, August 06, 2003 7:29 AM

Subject: [DUG]: Best methods for representing a 3 dimensional array

 

Morning all,

 

I need to code a structure that looks like this:

 

Q1 --- X1 --- F1

              --- F2

              --- F3

     --- X2 ---- F1

 

Q2 -- X2 --- F1

 

i.e. For every Q (highest level), there can be multiple X's. For every X, there can be multiple F's (lowest level). I want to create this structure and then be able to traverse it. E.g. Q1, X1, F1, then Q1, X1, F2, etc. right through the whole structure. Each Q, X, and F, are purely a string.

 

I thought about using a multidimensional dynamic array and using Delphi help could probably get this working. However, I'm new to Windows programming (1+ yrs) and want to learn OO. I've written a couple of objects recently, so thought I might try to tackle this as a Q object which has multiple X objects inside it, and then multiple F objects inside the X objects.

 

I've started reading about collections and trying some sample code, but don't know enough to "create a collection within a collection", or even if that's a correct concept.

 

Any comments or suggestions? Would a TObjectList be better? Should I just stick to an array?

 

TIA

Dave Jollie
Developer, TOWER NZ IT

(: 09 368 4259
J: 09 306 6801
*: [EMAIL PROTECTED]
.: 46 Parnell Rd, Parnell, Auckland

 

Reply via email to