Delphi 2009 where is the 'treat warnings as er

2020-07-02 09:04发布

问题:

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

回答1:

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



回答2:

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.



回答3:

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%