Jump to content
AlanScottAgain

Can an Object hold and object list of Itself?

Recommended Posts

Hi

I was wondering what the best way to approach this is?

Scenario:

I'm creating a simple drawing program based on Skia (Which is awesome)

I want to be able to create compound shapes.

 

My air code:


TDrawingObject= class

Brush

color

path

location

end;

 

Then

 

TDrawingObjectList = class (TObjectList<TDrawingObject>)

Holds and access the TDrawingObjects

How could I create something like:

 

TDrawingObject= class

Brush

color

path

location

DrawingObjectList

end;

 

So that I can recursively run through the one object that is made up of multiples of itself?

Thanks

Alan

 

Share this post


Link to post
Quote

So that I can recursively run through the one object that is made up of multiples of itself?

As long as you avoid or detect recursive infinite loops, then it is OK.

 

Share this post


Link to post

Thanks

 

How do I get past the issue that TDrawingObjectList  is not declared until after  TDrawingObject?  So  DrawingObject can't hold a list of DrawingObjectList 

TDrawingObjectList  can hold more TDrawingObjectList(s) 

 

I feel Like I'm missing something basic!  I can used an untyped list but that defeats the object.

I guess the question is how do I declare/ structure a recursive list. 

Share this post


Link to post

Just put this to the top:

 

type tDrawingObjectList = class;

Edited by Vandrovnik

Share this post


Link to post
10 minutes ago, Vandrovnik said:

Just put this to the top:

 

type tDrawingObjectList = class; 


But then its an untyped list?

I guess that may be the way to go

Share this post


Link to post
20 minutes ago, AlanScottAgain said:


But then its an untyped list?

I guess that may be the way to go

No, it is just a forward declaration.

Share this post


Link to post
Quote

But then its an untyped list?

No, it is a forward declaration. The class itself is declared after TDrawingObject.

That declaration is enough for the compiler to know it has to reserve space for the class field (Actually a pointer).

The code accessing the property DrawingObjectList is in the implementation section and after both classes have been completely defined.

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×