6

In CodeGear Delphi 2007, how can I turn specific warnings and hints off? I am attempting to turn off H2077 - Value assigned to 'varname' never used.

Dustin Venegas
  • 760
  • 1
  • 7
  • 16

5 Answers5

18

You are not able to disable specific hints like you can with warnings. Hints are those things that would not have any potential adverse affects on your runtime code. For instance, when you see the hint "Value assigned to 'varname' never used" it is merely a suggestion for something you should probably "clean up" in your code, but it won't cause any potential runtime errors (other than your own logic errors, of course :-). Hints are always best addressed by tweaking the code.

Warnings, on the other hand, are those things that could possibly cause unintended runtime behaviors and really should be addressed. For instance, using a variable before assigning a value to it is clearly a case of an uninitialized variable and that can lead to "bad things." In the vast majority of times, warnings should be addressed by "fixing" the code. Even then, in certain circumstances you may deem the warning as a "false positive" and are certain the code is functioning correctly. In those cases, you can disable a specific warning. Disabling all warnings is dangerous.

Allen Bauer
  • 16,657
  • 2
  • 56
  • 74
16

Hints? No specific.

You'll have to disable them all:

{$HINTS OFF}

Warnings?

{$WARN _name_of_warning_ OFF|ON|ERROR}

Check here for a full list

Johan
  • 74,508
  • 24
  • 191
  • 319
Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
9

Why don't you instead change the code so the hint goes away? Those hints are usually pretty accurate. And if you really feel that the line of code (I'm guessing some variable initialization or other) is useful to the reader of your code even if it is irrelevant to the compiler, you can replace it with a comment.

Jim
  • 4,691
  • 1
  • 25
  • 23
  • Jim, it's a program I inherited which has a billion of these. I'm trying to filter it down to be readable if there are any actual errors. The issue is, there variables are initialized to a specific value which is never used. It doesn't matter, it's just variable initialization. – Dustin Venegas Mar 10 '09 at 19:49
  • Dustin, it's not *just variable initialization*. Hints like that can point out problems in the code or paths of execution that you may not have considered. It takes just a couple of seconds to review the code and fix it, and you don't have to do it all at once. – Ken White Mar 10 '09 at 21:30
4

What Lars said. Also, you can get the complete list of warnings and their current settings by pressing CTRL-O twice. It'll dump a list at the top of the current unit. You can look through there to find the one you need to change. Just remember to delete the list later, or people looking at the code later on will hate you. ;)

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
3

To remove a hint for a line of code that has the:

H2077 Value assigned to '%s' never used

You can wrap it in:

{$HINTS OFF}
//...
{$HINTS ON}

For example, from the buggy Vcl.ComCtrls.pas:

procedure TTrackBarStyleHook.Paint(Canvas: TCanvas);
//....
begin
   if not StyleServices.Available then Exit;

   {$HINTS OFF}
   Thumb := ttbTrackBarDontCare; //value assigned to 'Thumb' never used
   {$HINTS ON}

   //...
end;

Note: Any code released into public domain. No attribution required.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219