views:

143

answers:

1

I have the following code in a Delphi 2007 application:

function TBaseCriteriaObject.RecursiveCount(
  ObjType: TBaseCriteriaObjectClass): integer;
var    
  CurObj: TBaseCriteriaObject;
begin
  result := 0;
{$WARNINGS OFF}
  for CurObj in RecursiveChildren(ObjType) do
    Inc(Result);
{$WARNINGS ON}
end;

Which produces this warning:

[DCC Warning] BaseCriteriaObject.pas(255): H2077 Value assigned to 'CurObj' never used

I understand the warning but don't want to change the code, so how do I get rid of the warning because {$WARNINGS OFF} does not seem to work in this case?

+4  A: 

From Delphi Help:

The $WARNINGS directive only works at the procedure or function level granularity. That is, you can surround entire procedures and functions with the $WARNINGS directive, but not blocks of statements within a procedure or function.

Serg
Cheers mate! It also appears to be a hint, not a warning. {$HINTS OFF} disables it (when around the procedure, not statement)
Alan Clark
The warning setting used for a function is whatever setting was in effect at the point it reached the function's `end`.
Rob Kennedy
@Rob Kennedy: Interesting remark. You must have seen the compiler sources :).
Serg
Nah. Just been around the block before. The same rule applies to the overflow checking (`{$Q}`), but not range checking (`{$R}`).
Rob Kennedy