从 DPR 文件中删除了编译器指令
问题
如何在DPR文件中制作编译器指令?
描述
我需要关闭此编译器警告,因为我不打算让我的库与C ++兼容。
如果我将编译器指令放入生成警告的PAS文件中,则将忽略。
如果我将其放入DPK文件中,则IDE每次更改项目选项时都会删除它(我们知道在更改选项时,DPK文件会部分重建)。
要重现它
- 启动delphi 10.4,
- 启动一个新的delphi软件包(文件主菜单)
- 添加{$ warn diplicate_ctor_dtor off} {$ in}之后。
- 现在打开项目选项,更改某些内容并关闭对话框。该指令将消失。
范围
此问题并未明确集中于“ deplate_ctor_dtor”,而是在DPR文件中使用用户添加的“ text”。
Question
How do I make a compiler directive stay in the DPR file?
Description
I need to turn off this compiler warning because I don't intend to make my library compatible with C++.
If I put the compiler directive in the PAS file that generates the warning, it is ignored.
If I put it in DPK files, the IDE will delete it every time I change the Project Options (we know that at when changing the options, the DPK file gets partially rebuilt).
To reproduce it
- Start Delphi 10.4,
- start a new Delphi package (File main menu)
- add {$WARN DUPLICATE_CTOR_DTOR OFF} after {$IMPLICITBUILD ON}.
- now open Project Options, change something and close the dialog. The directive will be gone.
Scope
This issue does not explicitly concentrates on "DUPLICATE_CTOR_DTOR" but in general on user-added "text" in DPR files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
转到Project≫ guts> building> delphi编译器>提示和警告,选择平台和配置,然后将其设置为
false
。并保存。 (根据您的Delphi版本,此设置的确切位置可能不同。)Go to Project>Options>Building>Delphi Compiler>Hints and Warnings, select the platform and configuration, then set that warning to
False
. And Save. (Depending on your version of Delphi, the exact location of this setting might be different.)在下面的 DPR 文件中,所有这些行在 Delphi 7 中都保持原样,即使 IDE 明智地保存/更改/添加了某些内容:
如您所见,我设置了一些编译器指令,而其他指令则被注释掉(前导点使其仅帕斯卡评论)。注释和空行也保留 - 没有任何内容被重写,尤其是指令。这就是为什么我要求您提供代码示例:您可能会在代码中使用除这些之外的位置。或者行为不同的 Delphi 版本。
即使 IDE 会从头开始重建您的 DPR,您也应该能够将一个单元添加到首先出现的项目中,并在其中放置编译器指令。编译器方面必须首先遇到这个问题。但我不知道你为什么不这样做,而且如果没有你的代码示例,我永远不会有任何线索。
In the following DPR file all these lines remain as-is in Delphi 7, even if IDE wise something is saved/changed/added:
As you see I set a few compiler directives, while others are commented out (the leading dot makes it only a Pascal comment). Comments and empty lines also remain - nothing is rewritten there, especially not the directives. That's why I ask for a code example by you: you might use a position in your code other than these. Or a Delphi version which behaves differently.
Even if the IDE would rebuild your DPR from scratch you should be able to add a unit to your project that comes first, and in that you put your compiler directive. Compiler wise this must be encountered first then. But I have no clue why you don't do so and never will have a clue without code examples by you.