我写了两个类 A,B 分别在 A.PAS ,B.PAS单元中 
其中
A.pas 
uses B而B.pas uses A
我知道把其中一个引用放在implementation下面就可以,但是问题是类A在interface的下面定义了一些成员方法,而这些成员方法的一些参数需要引用类B,而如果把Uses B放在
implementation下面,编译时系统报类B没有定义(找不到),估计是把Uses B放在
implementation下面时类A的成员方法都在 Uses B 语句的上面,编译时先编译了成员方法在编译引用语句所至。请教各位高手有什么解决方法-我的类A和类B都必须互相引用,而且各自的成员方法都在interface下并引用了类B。另外,我希望类似JAVA那样,一个类一个文件,上述问题如果把两个类放在一个unit单元内就可以解决。

解决方案 »

  1.   

    把两者的引用都放在
      interface下面引用
      

  2.   

    把两者的引用都放在
      interface下面引用就是会引起循环引用的错误啊!
      

  3.   

    uses一个在interface中,一个在implementation中;或两个都在implementation中;但决不可以都在interface中。因为在interface中的引用有传递关系:A引用B,B引用C,则A可以用C中的成员和方法(public,published...)理清楚你的类之间的关系,必要时要引入公共的基础类,没有解决不了的。
      

  4.   

    unit Unit2;interfaceuses unit3type
    CCtrl = class;                                                  CCtrl = class
       private
          FCunrrentThreadCount: integer;
          FCunrrentReceiveThreadCount: CMission;
    implementationend.
    _____________________________________-
    unit Unit3;interfacetype
       CMission = class
       public
          MissionID: integer;
          CNews : CCtrl;
       end;
    implementationuses unit2end.
    这时 CNews : CCtrl;会报错,因为uses unit2是在implementation下面,根本找不到unit2中定义的CCtrl类,放在interface下面uses unit2可以找到CCtrl,但是会引起循环引用错误,怎么解决?
      

  5.   

    type  CMission = class;  CCtrl = class
      private
        FCunrrentThreadCount: integer;
        FCunrrentReceiveThreadCount: CMission;
      end;  CMission = class
      public
        MissionID: integer;
        CNews : CCtrl;
      end;  TForm1 = class(TForm)
        Button1: TButton;
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      

  6.   

    findya(满地找牙) :你说的不错,但是我的第一个问题是:
    希望类似JAVA那样,一个类一个文件
      

  7.   

    暂时没有想到,不过你可以uses那个单元就可以了
    也可以把它写到.inc文件中,调用时候用{$I xxx.inc}
      

  8.   

    在implementation下面写uses就可以