unit Unit1;
//here
interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;
//here
{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
beginend;end.
//here
interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;
//here
{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
beginend;end.
这个问题我也想知道.
第二个use是此处需引用其他资源文件
在implementtion后面的是引用自己的单元.
不知这是你自己的理解还是从哪里看来的.
谢谢.
uses Unit2;
把Unit2放在前面的Uses中也可?
怎么回事?
当在上面引用某单元的话,如果本单元被别的单元引用,则本单元引用的某单元一并被别的单元引用,这样容易造成重复引用,产生编译错误,最好的方式为在下面引用。有一点需注意:引用一定要在使用(即:声明了待引用的单元对象或使用了待引用的单元内容)前。
系统的unit应该有一个机制,防止它被重复应用后重复定义.
而我自己的unit没有这种机制.
嗯,有道理.
否则,程序会报错!!!
而在下面引用的话,只有本单元可以访问到,对于其他单元不可见。
例如:UNIT1
interface
uses myunit1;
implementation
uses myunit2
假如有另一个单元UNIT2引用了UNIT1。则UNIT2也可以访问到MYUNIT1中的内容,而不用去再USES MYUNIT1。但是在UNIT1中的implementation中引用的MYUNIT2对于UNIT2是不可见的。
也就是说一个单元在INTERFACE接口部分声明的东西对于其他单元来说是可见的,是公开的。而在IMPLEMENTATION部分声明的东西对于其他单元来说是不可见的,是私有的。
这是OBJECT PASCAL中的解释,有兴趣可以看看这方面的书。
还是觉得coffee36(咖啡) 好理解些