Delphi Error – W1022 Comparison always evaluates to True

Delphi Compiler Error

W1022 Comparison always evaluates to True

Reason for the Error & Solution

The compiler has determined that the expression will always evaluate to true. This most often can be the result of a boundary test against a specific variable type, for example, a Integer against $80000000.

In versions of the Object Pascal compiler prior to 12.0, the hexadecimal constant $80000000 would have been a negative Integer value, but with the introduction of the int64 type, this same constant now becomes a positive int64 type. As a result, comparisons of this constant against Integer variables will no longer behave as they once did.

As this is a warning rather than an error, there is no standard method of addressing the problems: sometimes the warning can be ignored, sometimes the code must be rewritten.

program Produce;

  var
    i : Integer;
    c : Cardinal;

begin
  c := 0;
  i := 0;
  if c >= 0 then
    Writeln('true');

  if i < $80000000 then
    Writeln('true');
end.

Here the compiler determines that the two expressions will always be true. In the first case, a Cardinal, which is unsigned, will always be greater or equal to 0. In the second case, a 32-bit Integer value will always be smaller than an int64 value of $80000000.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...