阻止IDE自动添加使用单位

编程入门 行业动态 更新时间:2024-10-27 15:15:57
本文介绍了阻止IDE自动添加使用单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将一个Lazarus项目移至西雅图德尔福。

Lazarus项目取决于40多个单元(包括控件),并且有多个应用程序。

在所有项目的uses子句中,他们使用以下内容:

使用类,SysUtils,窗体,控件,图形,对话框,DBCtrl,{$ I OurLibrary.inc};

其中包括40多个单元,这些单元具有 $ I OurLibrary.inc 。

由于其中一些是控件,因此我在Delphi中对其进行了注册。

但是如果我保存项目或构建/编译它,Delphi会再次在使用部分添加单位。

类,SysUtils,表格,控件,图形,对话框,DBCtrl,uOurEdit,{$ I OurLibrary.inc};

在这种情况下,添加了 uOurEdit 单元甚至在 $ I OurLibrary.inc 中也可以。

如果我手动删除它并再次编译项目它运行。 一旦我切换回设计器模式并尝试运行它,同一件事不断发生-它再次添加了uOurEdit。再次添加。

是否有办法告诉Delphi完全停止读取单元或自动停止添加单元?

解决方案

IDE认为代码的某些部分受其控制。这包括许多DPR文件,表单或数据模块声明的默认已发布的部分以及用途 interface 部分的子句。最好不要在这方面打架。您最终会输掉的。

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

由于IDE在使用控件时会自动添加它们,因此您可以

您还可以考虑将单位列表移至用途子句。 IDE不会碰那个。

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?

解决方案

There are certain parts of your code that the IDE considers to be under its control. This includes much of the DPR file, the default published section of a form or data-module declaration, and the uses clause of the unit's interface section. It's best not to fight the IDE on this. You'll eventually lose.

I wouldn't recommend using an include directive in a uses clause. As you've already noticed, the IDE doesn't read the included file to determine the unit list. The Form Designer automatically adds units it thinks it needs, and there's no way to stop that.

Since the IDE will automatically add controls' units when they're used, you should be able to safely remove them from your include file anyway.

You might also consider moving your list of units to the uses clause in the implementation section. The IDE doesn't touch that one.

更多推荐

阻止IDE自动添加使用单位

本文发布于:2023-11-16 16:05:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605775.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单位   IDE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!