views:

575

answers:

3

In Delphi, you can use compiler directives to disable specific warnings, such as

{$WARN USE_BEFORE_DEF OFF}

But when I tried to do that with a specific hint, whose underscore_style_name I got out of the helpfile, the compiler said it doesn't know what {$HINT} is. So is there any way to do this?

+3  A: 

Best I can think of is to surround the subject of the hint with a conditional define, and use the same conditional define around the code that may or may not be needed, as shown below:

If you have this:

procedure MyProc;
var
  i : integer;
begin
  DoSomething;
  //SomethingWith_i_IsCommentedOut;
end;

You will get: Hint: variable "i" is declared but never used

So try this instead:

procedure MyProc;
  {$IFDEF USE_THE_I_PROCEDURE}
var
  i : integer;
  {$ENDIF}
begin
  DoSomething;
  {$IFDEF USE_THE_I_PROCEDURE}
  SomethingWith_i_IsCommentedOut;
  {$ENDIF}
end;

Now you can turn the define on or off, and you should never get a hint.

JosephStyons
+4  A: 

No specific hints, but you can disable them all.

{$HINTS OFF}
procedure MyProc;
var
  i : integer;
begin
  DoSomething;
end;
{$HINTS ON}
Lars Truijens
Yeah, that's what I was afraid of.
Mason Wheeler
+6  A: 

Little off-topic: You should take care about compiler's hints and warnings. They are not just for fun. Compiler is just saying "program may work differently that you think because YOUR source code is not exact".

DiGi
Yeah, hints are your friend. Don't hate on the hints.
Jim McKeeth
I took a look at Mason's code and showed him how to fix the hint. It was an undefined else condition. I've never met a hint or a warning that I couldn't fix. The compiler is my friend.
Jim McKeeth