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 E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...