Cannot get front class declaration to work in Delphi 2010

I was unable to get class declarations in Delphi 2010. I read documents, read on the Internet, and maybe I'm an idiot, but I just can't compile anything. Any help would be greatly appreciated!

I knocked down these two classes of mickey mouse. Of course, I know that they need constructors, etc. To actually work, this is just a demo for the problem I'm experiencing.

I have a MyParent class that contains the TList of my other MyChild class. It's great. But then inside MyChild, I want to be able to set a reference to its parent object, not to TList, but my MyParent class.

unit ForwardClassDeclarationTest; interface uses generics.collections; type MyChild = Class private ParentObect:MyParent; <--I need to be able to make this accessable public End; type MyParent = Class public tlChildren:TList<MyChild>; End; implementation end. 

I need to create a front declaration in front of both of these classes, but I completely cannot do anything. I thank everyone in advance who are inclined to help me.

+7
delphi
source share
2 answers

@csharpdefector try this code

 uses Generics.Collections; type MyParent = Class; // This is a forward class definition MyChild = Class private ParentObect:MyParent; public End; MyParent = Class // The MyParent class is now defined public tlChildren:TList<MyChild>; end; implementation end. 

for more information you can see this link in delphibasics

+13
source share

Before declaring MyChild, set: MyParent = class; and then declare MyChild. Then correctly declare MyParent. And do not reuse the type keyword. It denotes a type declaration block, not a separate type declaration, and the declaration of the class passing only works inside the same block.

+13
source share

All Articles