delphi

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


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 example, I'd like the compiler to stop on such warnings:

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

Delphi 10.3.2


Solution

  • 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.