帮我看一下这是什么错误(50分)

  • 主题发起人 主题发起人 hck555
  • 开始时间 开始时间
H

hck555

Unregistered / Unconfirmed
GUEST, unregistred user!
Circular unit reference to 'Unit1'<br>我编了两个单元。。。两个单元都互相调用。。。怎么出现上面的错误啊?
 
你是直接在interface下面的USES里面添加的unit1(unit2);<br>你改成在implementation下面<br>uses<br> &nbsp;unit1(unit2);<br>就没问题了。
 
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, unit2;<br>-------------------------------------------------------------<br>unit Unit2;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, unit1;<br><br>该成<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>uses<br> &nbsp;unit1;<br>---------------------------------------------<br>unit Unit2;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs;<br><br>type<br> &nbsp;TForm2 = class(TForm)<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form2: TForm2;<br><br>implementation<br><br>uses<br> &nbsp;unit1;<br>就OK了!
 
互相调用不太好<br>容易造成死循环
 
我改了以后。。。变成所有BEGIN语句都错了哦
 
你改的地方不对,正确的相互调用方法是:<br>把两个单元分人为的分为一个主单元和一个从单元(例如:主单元为A.pas,从单元为B.pas)。那么如下书写既可实现相互调用:<br>A.pas(主单元)如下:【注意将对单元B的引用部分放在implementation中了】<br>unit A;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, Menus;<br><br>type<br> &nbsp;TRLKind = (M,LJ);<br>.....<br> &nbsp;end;<br><br>var<br> &nbsp;fmViewForm: TfmViewForm;<br><br>implementation<br><br>uses<br> &nbsp;B;<br>{$R *.dfm}<br>....<br>end.<br><br>B.pas(主单元)如下:【注意将对单元B的引用部分放在interface部分了】<br>unit A;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, Menus, A;<br><br>type<br> &nbsp;TAKind = (M,LJ);<br>.....<br> &nbsp;end;<br><br>var<br> &nbsp;fmForm: TfmForm;<br><br>implementation<br><br>{$R *.dfm}<br>....<br>end.<br>但是,正如“镜中雪月”所说的,相互调用是不太好的。最好将公用部分写在第三个单元C中,然后A和B都去调用C中的代码。
 
哦。。。可以了。。谢谢
 
呵呵:) 不客气!可否考虑放分呢?
 
后退
顶部