Originale-mail to me for new edition

 

Forward declarations and mutually dependent classes

 

If the declaration of a class type ends with the word class and a semicolon, that is, if it has the form

type className = class;

with no ancestor or class members listed after the word class, then it is a forward declaration. A forward declaration must be resolved by a defining declaration of the same class within the same type declaration section. In other words, between a forward declaration and its defining declaration, nothing can occur except other type declarations.

Forward declarations allow mutually dependent classes. For example,

type

  TFigure = class;   // forward declaration

  TDrawing = class

    Figure: TFigure;

     ...

  end;

  TFigure = class    // defining declaration

    Drawing: TDrawing;

     ...

  end;

Do not confuse forward declarations with complete declarations of types that derive from TObject without declaring any class members.

type

  TFirstClass = class;           // this is a forward declaration

  TSecondClass = class           // this is a complete class declaration

    end;                          //

  TThirdClass = class(TObject);  // this is a complete class declaration

 

Topic groups

 

See also

About class types

TObject and TClass

 

 

译文

 

向前声明和相互依赖的类

 

如果一个类类型的声明以保留字class和紧随其后的分号结束,即具有如下形式

type className = class;

这里没有任何祖先或类成员列表于保留字class之后,那么,这是一个向前声明(forward declaration)。一个向前声明必需被同一个类的定义声明(defining declaration)解释,并且二者位于相同的类型声明节。换句话说,在向前声明和它的定义声明之间,除了其他的类型声明之外,不能出现任何其他内容。

向前声明允许实现互相依赖的类。例如,

type

  TFigure = class;   //向前声明

  TDrawing = class

    Figure: TFigure;

     ...

  end;

  TFigure = class    //定义声明

    Drawing: TDrawing;

     ...

  end;

不要混淆向前声明和起源于TObject类而没有声明任何类成员的类类型的完整声明。例如

type

  TFirstClass = class;           //这是一个向前声明

  TSecondClass = class           //这是一个完整的类声明

    end;                          //

  TThirdClass = class(TObject);  //这是一个完整的类声明

 

主题组

 

相关主题

关于类类型

TObjectTClass