如何实现在先声明的类里面调用后声明的类。如
unit xxxx;interfacetype
a = class
  private 
  public
      function Getb(): b;//问题处
end;type
b = class
  private 
  public
end;
...............................
不能改变所在的UNIT和声明先后顺序,请问各位大狭能否做到。

解决方案 »

  1.   

    f the declaration of a class type ends with the word class and a semicolon梩hat is, if it has the formtype className = class;with no ancestor or class members listed after the word class梩hen 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
      

  2.   

    type
      b = class;  a = class
      private
      public
        function Getb(): b;
      end;  b = class
        private
        public
      end;