views:

975

answers:

4

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.

+10  A: 

Hints? No specific. Warnings? Yes.

Lars Truijens
I checked both of those and can't seem to find the proper one for H2077. Do you have any ideas where these would be defined?
Dustin Venegas
H indicates a hint and hints can't be specifically ignored. You can however turn off all hints for that line.
Lars Truijens
Thanks for the quick and concise response!
Dustin Venegas
+7  A: 

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
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
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
+3  A: 

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
+14  A: 

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
I have found that the instances of false positives decreases as I learn to code better.
Jim McKeeth