Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop the Delphi compiler on a specific warning code?

Tags:

delphi

I'd like the compiler to stop on a given warning, like if it was an error.

The goal is to force taking into account warnings that could be really harmful to the code (not every warning is equal regarding severity)

For exemple, I'd like the compiler to stop on such warnings:

  • Result may not be initialized
  • Usage of a deprecated method
  • ...

I didn't find any option in the IDE, maybe in the command line compiler?

Delphi 10.3.2

Thanks,

like image 897
user315561 Avatar asked Oct 05 '19 12:10

user315561


1 Answers

This is documented: Warning messages (Delphi)

You use the compiler directive

{$WARN identifier ERROR}

to treat the warning named identifier as an error. The documentation page contains a list of all possible warnings. For instance,

{$WARN NO_RETVAL ERROR}

will treat

W1035 Return value of function '%s' might be undefined

as an error.

Update: As Sertac points out, you can also enable this setting globally for the project using Project Options, Bulding, Delphi Compiler, Hints and Warnings, Output warnings.

like image 115
Andreas Rejbrand Avatar answered Oct 20 '22 01:10

Andreas Rejbrand