You can do this using the $IFOPT directive:
{$IFOPT C+} // this block conditionally compiled if and only if assertions are active {$ENDIF}
So, you can rewrite your code as follows:
procedure Whatever; {$IFOPT C+} var v : Integer; {$ENDIF} begin {$IFOPT C+}v := {$ENDIF}DoSomething; {$IFOPT C+}Assert(v >= 0);{$ENDIF} end;
This will suppress the compiler hint, but it also makes your eyes bleed.
I would probably put it down like this:
procedure SuppressH2077ValueAssignedToVariableNeverUsed(const X); inline; begin end; procedure Whatever; var v : Integer; begin v := DoSomething; Assert(v >= 0); SuppressH2077ValueAssignedToVariableNeverUsed(v); end;
The unexplored parameter that the suppression function receives is sufficient to suppress the H2077. And using inline means that the compiler does not issue any code, since there is no function call.
David heffernan
source share