3

I am moving a Lazarus project to Delphi Seattle.

The Lazarus project depends on 40+ units (including controls) and has several applications.

In the uses clause of all the projects they used the following:

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, DBCtrls, {$I OurLibrary.inc};    

where they included those 40+ units with $I OurLibrary.inc.

As some of those units are controls i registered them in Delphi.

However if i save the project or build / compile it, Delphi adds the units in the uses part again.

  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, DBCtrls, uOurEdit, {$I OurLibrary.inc}; 

In this case the unit uOurEdit got added again even tho it is in $I OurLibrary.inc.

If i manually delete it and compile the project again it runs. Once i switch back in designer mode and try to run it the same thing keeps happening - it adds uOurEdit again.

Once you remove a unit Lazarus doesn't add it again. Delphi does that.

Is there are way to tell Delphi to stop readding units or stop add units automatically at all?

4

2 回答 2

10

IDE 认为代码的某些部分在其控制之下。这包括大部分 DPR 文件、published表单或数据模块声明的默认部分以及uses单元部分的子句interface。最好不要在这方面与 IDE 抗争。你最终会输。

我不建议在子句中使用include指令。uses正如您已经注意到的,IDE 不会读取包含的文件来确定单元列表。表单设计器会自动添加它认为需要的单元,并且没有办法阻止它。

由于 IDE 在使用时会自动添加控件的单元,因此您应该能够安全地从包含文件中删除它们。

您也可以考虑将您的单位列表移动到uses该部分的子句中implementation。IDE 不会触及那个。

于 2015-11-12T16:32:18.450 回答
2

我同意使用包含文件不是一个好主意,但实际上有一种方法可以阻止 IDE 自动添加这些单元。

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, DBCtrl,
  {$IFDEF DUMMY}
  // add those units here which you don't want to automatically add
  // the IDE won't add them but they won't be part of the uses assuming
  // DUMMY is undefined
  uOurEdit,
  {$ENDIF}
  // Here comes the rest of the units
  {$I OurLibrary.inc};

这可能对您不起作用,因为uOurEdit无论如何您都必须手动添加,所以最好听从 Rob 的建议。但是,此技术可用于停止 IDE 自动添加单元。

于 2015-11-13T01:56:43.210 回答