HomeDelphiDelphi Error – E2012 Type of expression must be BOOLEAN

Delphi Error – E2012 Type of expression must be BOOLEAN

Delphi Compiler Error

E2012 Type of expression must be BOOLEAN

Reason for the Error & Solution

This error message is output when an expression serves as a condition and must therefore be of Boolean type. This is the case for the controlling expression of the if, while and repeat statements, and for the expression that controls a conditional breakpoint.

program Produce;
var
  P: Pointer;
begin
  if P then
    Writeln('P <> nil');
end.

Here, a C++ programmer just used a pointer variable as the condition of an if statement.

program Solve;
var
  P: Pointer;
begin
  if P <> nil then
    Writeln('P <> nil');
end.

In Delphi, you need to be more explicit in this case.

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...