Ad Space — Top Banner

E2251

Delphi Programming Language

Severity: Minor

What Does This Error Mean?

E2251 means you called an overloaded function and Delphi cannot decide which version to use because multiple versions match the arguments you passed. Overloaded functions are multiple functions with the same name but different parameter types. When Delphi cannot tell which one you want, it gives E2251. The fix is to make the call unambiguous by adding a type cast to specify which parameter type you mean.

Affected Models

  • Delphi 4 and later
  • Delphi 7
  • Delphi XE
  • Delphi 10.x
  • Delphi 11
  • Delphi 12
  • All modern Delphi versions

Common Causes

  • Calling an overloaded function with an argument that could match multiple overload variants
  • Integer literals like 1, 0, or -1 can match Integer, Int64, Single, Double, etc. — causing ambiguity
  • Passing a variable whose type is compatible with multiple overload parameter types
  • String literals can match String, AnsiString, or WideString overloads in some Delphi versions
  • A nil literal is ambiguous when multiple overloads accept pointer or class parameters

How to Fix It

  1. Add a type cast to the argument to tell Delphi which overload to use.

    Example: if Show(x) is ambiguous, try Show(Integer(x)) or Show(Double(x)) to specify which version you want.

  2. For numeric literals, cast to the specific type: Show(Integer(1)) for an integer overload, Show(Double(1)) for a floating-point overload.

    The number 1 is ambiguous — it could be Integer, Cardinal, Int64, Single, or Double. Casting it makes your intent clear.

  3. For nil passed to overloaded functions that accept class or pointer types, cast nil to the specific type: DoSomething(TMyClass(nil)) or DoSomething(PMyRecord(nil)).

    Nil is typeless — Delphi cannot infer which pointer or class type you mean when multiple overloads accept different types.

  4. If you control the overloaded function, consider whether the overloads are too similar. Making parameter types more distinct can eliminate ambiguity entirely.

    Good overload design uses clearly distinct parameter types so callers rarely need type casts.

  5. Check the Delphi documentation or overload declarations to see exactly which parameter types each version expects — then cast your argument to the matching type.

    In the IDE, Ctrl+Click on the function name shows all overload declarations. This helps you see which types to cast to.

When to Call a Professional

E2251 is a compile-time error you can always fix by adding an explicit type cast. This tells Delphi exactly which type you mean, resolving the ambiguity.

Frequently Asked Questions

What is function overloading in Delphi?

Function overloading means defining multiple functions with the same name but different parameter types. Delphi introduced overloading in Delphi 4 with the 'overload' directive. Example: function Add(A, B: Integer): Integer; overload; and function Add(A, B: Double): Double; overload; Delphi chooses the right version based on the types of the arguments you pass.

How do I add the overload directive to my function?

Add the word 'overload' after the function signature: procedure Show(Value: Integer); overload; procedure Show(Value: Double); overload; procedure Show(Value: string); overload; All versions must have the 'overload' directive — not just the extras.

Why does Delphi struggle with integer literals in overloaded calls?

Because integer literals have no fixed type in Delphi — the compiler chooses a type based on context. A literal like 42 could match Integer, Cardinal, Int64, Byte, Word, Single, or Double. When multiple overloads accept these numeric types, Delphi cannot automatically choose. The solution is explicit type casting: Show(Integer(42)) — you tell the compiler exactly which type to use.