Ad Space — Top Banner

E2016

Delphi Programming Language

Severity: Moderate

What Does This Error Mean?

E2016 means you used a non-boolean expression where Delphi requires a true/false result. This most often happens in an if statement, while loop, or repeat condition where you wrote an integer or string instead of a Boolean comparison. Fix it by adding an explicit comparison operator such as = or <> to produce a Boolean result.

Affected Models

  • Delphi 10.4 Sydney
  • Delphi 11 Alexandria
  • Delphi 12 Athens
  • Embarcadero RAD Studio
  • Free Pascal / Lazarus

Common Causes

  • Writing if MyInteger then instead of if MyInteger > 0 then
  • Passing a function result that returns an integer directly to an if condition
  • Using a string variable as a condition instead of comparing it with = or <>
  • Assigning the result of a bitwise operation to a Boolean variable without a comparison
  • Confusing an assignment := with a comparison = inside a condition

How to Fix It

  1. Find the line the IDE highlights and look at the condition expression.

    The condition must evaluate to Boolean (True or False). Any other type will cause E2016.

  2. If you have an integer, add an explicit comparison: change if Count then to if Count > 0 then.

    Unlike C, Delphi does not treat non-zero integers as true. You must write the comparison explicitly.

  3. If you have a string, compare it: change if UserName then to if UserName <> '' then.

    An empty string check uses <> '' and a non-empty check also uses <> '' or Length(UserName) > 0.

  4. If you are calling a function, make sure its return type is Boolean, not Integer or another type.

    If the function returns an integer error code, compare it: if GetResult = 0 then instead of if GetResult then.

  5. If the line uses a bitwise and or or, wrap the comparison in parentheses: if (Flags and 1) <> 0 then.

    Bitwise operations return integers in Delphi. You must compare the result to a number to get a Boolean.

When to Call a Professional

This is a compiler error — no professional repair needed. Fix it by reading the error message and correcting the code. The Delphi IDE highlights the exact line causing the problem.

Frequently Asked Questions

Why does Delphi not accept integers as conditions like C does?

Delphi is a strongly-typed language — it requires conditions to be explicitly Boolean. In C, zero means false and any other value means true, which is a common source of bugs. Delphi's approach is stricter but makes the code intent clearer and prevents accidental mistakes.

What Boolean types does Delphi support in conditions?

Delphi accepts Boolean, ByteBool, WordBool, and LongBool in conditions. All four evaluate to True or False, though they differ in size and how they store the value internally. In practice, use Boolean for all standard conditions.

Can I test whether a pointer is nil using an if statement?

Yes — if Assigned(MyPointer) then or if MyPointer = nil then are both valid Boolean expressions. Assigned() is the recommended Delphi function for nil checks on pointers and object references. Do not write if MyPointer then — that will produce E2016.