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