Search code examples
delphidelphi-7

Remove compiler warning about symbol declared but not used


I've declared some methods which occasionally get used for debugging only. For example:

// For debugging purposes only
{$IFDEF DBG}
procedure SaveLUTs();
{$ENDIF}

These methods are used rarely and only if DBG is defined. If the method is not used the following compiler warning is generated:

[Hint] Hardware.pas(184): Private symbol 'SaveLUTs' declared but never used

Apart from commenting out the method declaration and body, is there a way to mark SaveLUTs so that the compiler won't generate the warning? I still need the usual warnings to be generated, including warnings about other declared methods or variables that are not used.

Using Delphi 7 and interested in how this might be done for newer versions of Delphi as well.


Solution

  • You can flag the method like this :

    {$Hints Off}
    procedure SaveLUTs();
    {$Hints On}
    

    That will remove the hint for this procedure.

    Note that {$Hints ON} will enable hints for the rest of the unit regardless of the previous $Hints state. Since {$IFOPT} doesn't work with long-named directives (At least, up to Delphi 10 Seattle...), I don't know of any way to restore the previous state.