Delphi Error – W1021 Comparison always evaluates to False

Delphi Compiler Error

W1021 Comparison always evaluates to False

Reason for the Error & Solution

The compiler has determined that the expression will always evaluate to False. 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 Delphi 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('false');

  if i >= $80000000 then
    Writeln('false');
end.

Here the compiler determines that the two expressions will always be False. In the first case, a Cardinal, which is unsigned, can never be less than 0. In the second case, a 32-bit Integer value can never be larger than, or even equal to, 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...