1

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.

People on the mighty internet say that {$WARN DUPLICATE_CTOR_DTOR OFF} should be placed in the DPR file. It works. But if you put in in DPK files, the IDE will delete it every time I change the Project Options (we all know that at when changing the options, the DPK file gets partially rebuilt).

Question: How do I make the directive stay in the DPK file?

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.
Gabriel
  • 20,797
  • 27
  • 159
  • 293
  • Once more: add code as an example that allows others to reproduce what you experience , because by far not everything in a DPR is rewritten from scratch when it is saved. – AmigoJack Apr 03 '22 at 13:04

2 Answers2

3

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.) Screenshot of warning setting

  • Why would it get deleted? I always turn that one off in the options, and don't have a problem with the .dproj file getting deleted. – Philip J. Rayment Apr 04 '22 at 13:38
  • So what happens if the .dpr/.pas file gets deleted? My point is that it needs to be saved _somewhere_, and that _somewhere_ could always get deleted somehow. Yes, the IDE itself plays around with the .dpr file and sometimes messes things up, but the .dproj file seems pretty safe. – Philip J. Rayment Apr 05 '22 at 10:13
  • Hi Philip :) - Dproj is not a "mandatory" Delphi file. If you go on GitHub (or where ever on Internet) you will have many Delphi projects delivered without Dproj files. This is why (even though I agree with your solution) I would like to find a way to make the IDE keep the directive in the Dpk file. – Gabriel Apr 05 '22 at 11:36
  • Why would it get deleted?" - To clarify: I never said that the dproj file gets deleted by the IDE. I said that the {$WARN DUPLICATE_CTOR_DTOR OFF} text gets deleted from Dpk :) – Gabriel Apr 05 '22 at 11:36
  • PS: This is not really the answer that I was looking for. I need the directive in the DPK file, not in the DPROJ. If someone else offers a better solution/answer, I will accept it. – Gabriel May 25 '22 at 10:13
0

In the following DPR file all these lines remain as-is in Delphi 7, even if IDE wise something is saved/changed/added:

// My comment
{.$DEFINE MEMCHECK}
{$DEFINE BOMB}
// JCL_DEBUG_EXPERT_GENERATEJDBG ON
// JCL_DEBUG_EXPERT_INSERTJDBG ON
program pMain;

{$SetPEFlags $c20}
{.$define FullDebugMode}
{$I all.inc}

uses
  FastMM4,
  madExcept,

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.

AmigoJack
  • 5,234
  • 1
  • 15
  • 31
  • Hi. Sorry. My mistake! It only happens with DPK files. I got the impression that the bug appears also in the DPR but it does not. To reproduce it: Start Delphi 10.4, start a new Delphi package (File main menu) and add {$ENDIF IMPLICITBUILDING} after {$IMPLICITBUILD ON}. Now open Project Options, change something and close the dialog. The IMPLICITBUILDING directive is gone. – Gabriel Apr 05 '22 at 11:32
  • Man! People are still using Delphi 7 today! I think Delphi 7 was the most glorious release :) – Gabriel Apr 06 '22 at 16:07