AlanScottAgain 1 Posted June 14, 2022 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
FPiette 382 Posted June 14, 2022 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
AlanScottAgain 1 Posted June 14, 2022 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
Vandrovnik 214 Posted June 14, 2022 (edited) Just put this to the top: type tDrawingObjectList = class; Edited June 14, 2022 by Vandrovnik Share this post Link to post
AlanScottAgain 1 Posted June 14, 2022 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
Vandrovnik 214 Posted June 14, 2022 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
FPiette 382 Posted June 14, 2022 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. 1 Share this post Link to post
AlanScottAgain 1 Posted June 14, 2022 Thank you I did not know about forward declarations 👍 Share this post Link to post