E2015
Delphi Programming Language
Severity: ModerateWhat Does This Error Mean?
Error E2015 means you used an operator (like +, -, *, /, =, <, >) on a type that does not support that operator. Not every type supports every operator in Delphi. For example, you cannot use arithmetic operators on a record type or compare two arrays with =.
Affected Models
- Delphi 2005 and later
- RAD Studio
- Lazarus/Free Pascal (similar error)
Common Causes
- Trying to add, subtract, or multiply two records or objects using standard arithmetic operators
- Comparing two arrays, records, or objects with = or <> without overloading those operators
- Using a bitwise operator (and, or, xor) on a non-integer type like a float or string
- Applying the not operator to a non-Boolean value
- Using arithmetic on an enumerated type without a typecast
How to Fix It
-
Read the error message to identify which operator and which type are involved.
Example: 'Operator not applicable to this operand type' on a line with '+' and a record type.
-
Instead of using = to compare two records or objects, write a dedicated comparison function or method that compares the fields you care about.
Example: function RecordsAreEqual(A, B: TMyRecord): Boolean; — compare each field inside.
-
For arithmetic on custom types, overload the operator in the record or class definition using the 'operator' keyword (available in modern Delphi).
Example: class operator Add(A, B: TVector): TVector; — this lets you write V1 + V2 for your TVector type.
-
If you are trying to use bitwise operations on a float, convert to an integer type first using Round(), Trunc(), or a bitcast. Bitwise operations only make sense on integer types.
Example: Integer(FloatVar) and $FF — but be careful, this reinterprets the bits, not the value.
-
For enumerated types, cast to integer before performing arithmetic: Integer(MyEnum) + 1. Then cast back if needed: TMyEnum(Integer(MyEnum) + 1).
Be careful: Delphi's type system will not warn you if the result is outside the valid range of the enumeration.
When to Call a Professional
E2015 is always something you can fix yourself. The fix is either to use the correct approach for your type (like a comparison function instead of =), or to overload the operator in your class or record.
Frequently Asked Questions
Can I make Delphi support + or = on my own types?
Yes — Delphi supports operator overloading for records (not classes). You define special class operator methods inside the record declaration. This lets you write natural mathematical expressions with your own types, like vectors, complex numbers, or money amounts.
Why can I compare integers with = but not records?
Integer equality is well-defined — two integers are equal if their numeric value is the same. Record equality is ambiguous — does 'equal' mean all fields match? Some fields? A specific field? Delphi leaves this decision to you by requiring an explicit comparison function or operator overload.
What is operator overloading and is it a good idea to use it?
Operator overloading lets you define what +, -, =, etc. mean for your custom types. It is a good idea when it makes the code significantly more readable — like defining + for a Vector type so you can write V1 + V2. Avoid it for types where the meaning would not be obvious, as it can make code confusing to read.