2

Compiler hints are being included in the build messages as warnings when I compile any project on my installation of Delphi 2007, like so:

[DCC Warning] Unit1.pas(30): H2077 Value assigned to 'i' never used

In my real project this persists even when I disable Show hints in the project options, however in a new test project this setting does hide these lines. Other people seem to see hints preceded by [DCC Hint], is there any way I can fix this?

Jamie Kitson
  • 3,973
  • 4
  • 37
  • 50
  • 1
    Not to nag, but why do you care about this - shouldn't your code just compile without warnings and messages? They are there for a reason – Jan Doggen Aug 20 '15 at 12:56
  • Hints and warnings are quite different: a) hints should not impact the running of your code and can often be legitimately ignored; and b) you can't disable specific hints. eg see: http://stackoverflow.com/a/632328/139560 – Jamie Kitson Aug 20 '15 at 13:06
  • I would never ignore either. Hints may be ignored, but they are a sign that something is not quite right, so I would not ignore them. – Rudy Velthuis Aug 20 '15 at 20:51

1 Answers1

2

The QC entry reporting this issue eight years ago was closed because it couldn't be reproduced, so there is likely no fix.

You might try deleting your project's .dsk file. That sometimes helps make spurious IDE issues go away.

Your most immediate course of action is "tweaking the code," as compiler developer Allen Bauer suggests in the answer you cited in comments. Hints might still indicate problems in your code, such as unfinished algorithms. When you get complacent about compiler messages, then you're less likely to notice when a new one crops up that really does require attention.

Eventually, you'll want to upgrade to a more recent Delphi version.

Community
  • 1
  • 1
Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • Thanks. I didn't actually want to hide hints, but I would like to be able to easily distinguish between hints and warnings. – Jamie Kitson Aug 20 '15 at 16:42
  • 1
    In my experience, most people don't care to distinguish between them. Rather, *any* compiler message is a message that must be addressed immediately. – Rob Kennedy Aug 20 '15 at 16:48
  • I'd rather eliminate all hints and warnings in my code, making the difference between them irrelevant. – Ken White Aug 21 '15 at 03:20
  • As an example is it better to use `StrToInt` in a `try...except` block rather than `Val` because of _H2077 Value assigned to 'i' never used_? – Jamie Kitson Aug 21 '15 at 10:52
  • If you're getting a message from using `Val`, then I suppose you're not checking for errors. That's easy to fix. Also consider `TryStrToInt` or `StrToIntDef`. The main reason to use `Val` is if you need the `Code` parameter to tell you which character caused the conversion to stop. If you don't use that parameter, then the compiler will tell you. (It tells you about *that* unused "var" parameter and not others because `Val` is compiler magic that gets inlined *before* the compiler performs its data-flow analysis to detect unused variables.) – Rob Kennedy Aug 21 '15 at 11:59
  • The compiler message comes because the resultant int is not being used. – Jamie Kitson Aug 21 '15 at 23:40
  • 1
    I see. You want to know whether a string contains an integer, but you don't care what value it has. Use `TryStrToInt`. The "unused" var parameter from that function won't trigger a hint from the compiler because the compiler considered all var parameters to be used (except the one for `Val`, because that function is magic). – Rob Kennedy Aug 21 '15 at 23:58