Delphi Error – E2015 Operator not applicable to this operand type

Delphi Compiler Error

E2015 Operator not applicable to this operand type

Reason for the Error & Solution

This error message is given whenever an operator cannot be applied to the operands it was given – for instance if a boolean operator is applied to a pointer.

program Produce;
var
  P: ^Integer;
begin
  if P and P^ > 0 then
    Writeln('P points to a number greater 0');
end.

Here a C++ programmer was unclear about operator precedence in Delphi – P is not a boolean expression, and the comparison needs to be parenthesized.

program Solve;
var
  P: ^Integer;
begin
  if (P <> nil) and (P^ > 0) then
    Writeln('P points to a number greater 0');
end.

If we explicitly compare P to nil and use parentheses, the compiler is happy.

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