我完全无法在Delphi 2010中获得类声明.我已经阅读了文档,在网上阅读,也许我是一个白痴,但我无法得到任何编译.任何帮助都将受到大力赞赏!
我敲了这两个米老鼠班.当然,我知道他们需要构造函数等来实际工作,它只是我正在解决的问题的演示.
我有MyParent类,其中包含我的其他类MyChild的TList.没关系.但是在MyChild中我希望能够设置对其父对象的引用,而不是TList而是MyParent类.
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.
Run Code Online (Sandbox Code Playgroud)
我需要在这两个类之前创建一个前向声明,但我完全无法得到任何结果.提前感谢任何倾向于帮助我的人.
RRU*_*RUZ 13
@csharpdefector试试这段代码
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.
Run Code Online (Sandbox Code Playgroud)
有关更多信息,您可以在delphibasics中看到此链接
Mas*_*ler 13
在声明MyChild之前,先输入:MyParent = class;
然后声明MyChild.然后正确声明MyParent.并且不要重复使用type关键字.它表示一个类型声明块,而不是一个单独的类型声明,而类前向声明只能在同一个块中工作.
归档时间: |
|
查看次数: |
5921 次 |
最近记录: |