E2012 Type of expression must be BOOLEAN (Object Pascal)

From Appmethod Topics
Jump to: navigation, search

Go Up to Error and Warning Messages (Object Pascal) Index

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 Object Pascal, you need to be more explicit in this case.