如何在不修改给定单元的情况下禁用该单元的警告?

发布于 2024-11-18 21:26:27 字数 441 浏览 3 评论 0原文

因此,我在我的单元中包含了一些其他单元,在构建应用程序后,我收到了来自这些单元的大量警告。数量如此之大,以至于我在列表中找到自己的警告时遇到了问题。 ;-)

是否有一些编译器指令可以让我关闭这些警告?但请注意,我不想以任何方式修改这些单位。我想实现这样的目标:

unit MyUnit;

interface

uses
  UnitA, {$WARN EMIT_WARNNIGS OFF} UnitB, {$WARN EMIT_WARNNIGS ON} UnitC, UnitD.

implementation

uses
  UnitE, {$WARN EMIT_WARNNIGS OFF} UnitF, UnitG, {$WARN EMIT_WARNNIGS ON} UnitH.

这是一个我想要的虚构的编译器指令,或者它可能存在但我不知道?

感谢您抽出时间。

So I am including in my unit some other units and after building application I receive a huge amount of warnings from those units. The amount is so large that I'am having problems in finding my own warnings on the list. ;-)

Is there some compiler directive which would allow me to turn those warnings off? But please note, that I don't want to modify those units in any way. I would like to achieve something like this:

unit MyUnit;

interface

uses
  UnitA, {$WARN EMIT_WARNNIGS OFF} UnitB, {$WARN EMIT_WARNNIGS ON} UnitC, UnitD.

implementation

uses
  UnitE, {$WARN EMIT_WARNNIGS OFF} UnitF, UnitG, {$WARN EMIT_WARNNIGS ON} UnitH.

This is an imaginary compiler directive which I would like to have, or maybe it exists and I don't know about it?

Thanks for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

羁〃客ぐ 2024-11-25 21:26:27

有一个编译器指令可以关闭警告,但这只能在项目选项中设置(在这种情况下它适用于所有单元)或在单元本身中设置(在这种情况下它仅适用于该单元)。

所以,你有几个选择。

不切实际的选项完全符合您的要求:

因此,唯一的解决方案是在项目中禁用警告,然后使用该指令在您自己的所有单元中启用它们。

最简单、最现实的选项:

编译单元一次,并且仅通过从库路径中删除源来使用 DCU。如果您无论如何都不想编辑它们,这是最简单的。

您仍然可以将它们添加到与库路径不同的浏览路径中。在这种情况下,将使用 DCU,但 Delphi 仍然可以找到源代码,因此您仍然可以在调试时导航它们。

一个小的优点是构建项目也更快,因为这些单元不需要在每次构建时重新编译。

最佳选择:

完全停止使用这些设备。具有如此多警告的设备都是劣质软件,可能会导致严重问题。

其他解决方案:

  • 放弃不修改单元的愿望,无论如何将编译器指令添加到这些单元中
  • 解决警告

There is a compiler directive to turn warnings off, but this can only be set in either project options in which case it applies to all units, or in a unit itself in which case it applies to that unit alone.

So, you're left with a few options.

Unrealistic option that does exactly what you ask:

So the only solution would be to disable warnings in your project and then enable them in all your own units using that directive.

Easiest and most realistic option:

Compile the units once and only use the DCUs by removing the source from your library path. That's easiest if you do not want to edit them anyway.

You can still add them in your browsing path which is different from the library path. In that case, the DCUs are used, but Delphi can still find the sources, so you can still navigate them whilst debugging.

Small advantage is that building your project is faster too, because these units don't need to be recompiled on each build.

Best option:

Stop using those units at all. Units with so many warnings are inferior software and can cause serious problems.

Other solutions:

  • Set aside your wishes of not modifying the units and add the compiler directives to those units anyway
  • Solve the warnings
自我难过 2024-11-25 21:26:27

我使用 Delphi 7,这是我的做法...

不要将单元包含在项目 .dpr 中,否则这将不起作用,将单元的文件夹添加到项目选项的搜索路径上。

然后在您使用它的每个单元中,使用这些编译器指令:

  uses
    {$WARNINGS OFF}{$HINTS OFF}
    TheUnitHere;
    {$WARNINGS ON}{$HINTS ON}

I use Delphi 7 and here's how I do it...

Do not include the unit it the project .dpr or this will not work, add the folder of the unit on the search path of the Project Options.

Then in every unit you use it, use these compiler directives:

  uses
    {$WARNINGS OFF}{$HINTS OFF}
    TheUnitHere;
    {$WARNINGS ON}{$HINTS ON}
白鸥掠海 2024-11-25 21:26:27

不,我不相信有这样的指令。

我发现实现此目的的唯一方法是

  • 编译所有内容,
  • 将有问题的单元的 dcu 放在编译器会找到它的地方,
  • 确保在该 dcu 的源之前找到 dcu,或者确保无法找到源编译器

这将确保 pas 不会被编译,这样您就不会被来自违规单元的警告所淹没。

当我不希望调试器单步执行库单元(我们总是从源代码编译)时,我经常采用这种方法。我编译发布配置(debug = off),然后选择我不想进入的单元的 dcu,并确保编译器在相应的 pas 文件之前找到它们。

需要注意的是:确保当你(需要)处理有问题的单位时,DCU 会被移除,否则你会陷入很多混乱。 GExperts 的“清理目录”可以帮助解决这个问题。

No, I don't believe there is such a directive.

The only way I have found to achieve this, is to

  • compile everything
  • put the dcu of the offending unit somewhere where the compiler will find it
  • make sure the dcu is found BEFORE the source for that dcu, or make sure the source cannot be found by the compiler

This will ensure that the pas is not compiled so you won't be swamped by the warnings from the offending units.

It is an approach I often take with library units (which we always compile from source) when I do not want the debugger stepping into them. I compile the release configuration (debug = off) then pick up the dcu's of the units that I do not want to step into and make sure that they are found by the compiler before their corresponding pas files.

One caveat: make sure that when you (need to) work on the offending units, the dcu gets removed, or you will be in for a lot of confusion. GExperts' "Clean directories' can help with this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文