16

In Delphi 2009 whereabouts do you turn on the option to treat warnings as errors?

RRUZ
  • 134,889
  • 20
  • 356
  • 483
Jamie
  • 3,150
  • 2
  • 26
  • 35

3 Answers3

20

Just found the answer soon after I posted this! Might be useful for other people.

Navigate to 'Project -> Options - > Delphi Compiler -> Hints and Warnings' and change the value of 'Output Warnings' to 'as errors'

I was looking for an option similar to what Visual Studio has

Jamie
  • 3,150
  • 2
  • 26
  • 35
  • 1
    I had looked right at that screen but never did the drop down to see the "as errors" option. When I saw True as the default I just assumed "False" was the only other option. Thanks! – Jim McKeeth Nov 06 '08 at 18:17
  • This is just for the project you are on at the time. What if I always want all warnings in all projects to be errors? (I really want hints to be the same but I don't think that is possible). – Paul Aug 06 '18 at 20:54
  • 1
    @Paul You probably have to set it on all of the projects individually. It's being set in the project files, so you can write a script to set them all at once. Stick this in a `PropertyGroup` tag with no condition: `error` (for each dproj file). – Millie Smith Aug 16 '18 at 01:25
  • Thanks but no luck. The program always compiles as success even after reporting a warning. I have added this to every configuration using the GUI and editing the DPROJ file manually. Seems this option is broken in Delphi 10. – Paul Aug 16 '18 at 13:58
  • @Paul I noticed the same in my Delphi 10.2 project. When set to 'as errors' the compiler would not convert warnings to errors. However, I did find out that I had some warnings set to False (platform symbols and platform units). When I set them back to True (the default), all warnings are converted to errors. It just does not work anymore when you change any of the defaults in the list of warnings. I am still looking for a solution to disable some warnings globally (for the whole project), but have all other warnings converted to errors. I do not know how to do that... – R. Beiboer Apr 29 '20 at 08:04
15

On a related note, if you are using the command line compiler (DCC32.exe) the switch is -W^ to have warnings treated as errors. If you are using this, it's important to note that the default command shell in Windows (cmd.exe) treats the caret (^) as an escape character, so you have to use -W^^ instead if you are executing the compiler directly from the command line, a batch file or even the from the Pre-Build or Post-Build events in the IDE.

It's also worth mentioning that you can have only certain warnings treated as errors. The switch to do this on the command line would look something like this: -W^^WARNING-NAME. You would substitute the string that is associated with the warning you are wanting to have treated as an error.

Mark Edington
  • 6,484
  • 3
  • 33
  • 33
2

The point about -W^ being problematic within BAT files is a good one. Using -W^^ works if you are modifying the compile line directly. Otherwise, I found that using surrounding double quotes "-W^" works, for example when building an env var that contains all compiler parameters, that env var being subsequently passed to dcc32.exe. Tested with XE, XE2, XE3, XE4.

SET CompilerParams=-B -M "-W^" -U"..\Source;%dcuoutdir%;%DUnitPath%" -I"..\Source\inc" "-N0%dcuoutdir%" -DDebugMode
"%dcc%bin\dcc32.exe" %FuTFolder%ADDTests.dpr %CompilerParams% -U"%FuTSource%" %ExtraPath32%>%DCCLogFilename%
if errorlevel 1 %Alerter% %DCCLogFilename%
user424855
  • 233
  • 1
  • 2
  • 8