按教程上的方法做一个最简单的Com服务器程序,发现自动生成程序如下:
interfaceuses
ComObj, ActiveX, AutoSrv_TLB, StdVcl, Unit1;type
TMyAutoSrv = class(TAutoObject, IMyAutoSrv)
protected
function Get_Caption: WideString; safecall;
procedure Set_Caption(const Value: WideString); safecall;
procedure SetColor(AColor: OLE_COLOR); safecall;
procedure SetEditText(const AText: WideString); safecall; end;implementationuses ComServ;奇怪的是uses ComServ;被放在了Implementation部分,而ComServ.pas和Windows.pas一样,都是Delphi自带的文件。这个有什么原因在里面吗?
interfaceuses
ComObj, ActiveX, AutoSrv_TLB, StdVcl, Unit1;type
TMyAutoSrv = class(TAutoObject, IMyAutoSrv)
protected
function Get_Caption: WideString; safecall;
procedure Set_Caption(const Value: WideString); safecall;
procedure SetColor(AColor: OLE_COLOR); safecall;
procedure SetEditText(const AText: WideString); safecall; end;implementationuses ComServ;奇怪的是uses ComServ;被放在了Implementation部分,而ComServ.pas和Windows.pas一样,都是Delphi自带的文件。这个有什么原因在里面吗?
uses ComServ; //相当是局部的声明估计有“循环引用”的问题,所以没有放在头部声明。
1.如果你在定义域用到了你要use的单元,那么就要放在上面,不然编译不了。
2.放在下面,编译的时候不会去编译你use的单元中use的单元,放在上面则在编译use的单元时,会编译你use的单元中use的单元。所以放在下面不会造成循环引用的问题。