Delphi Error – E2266 Only one of a set of overloaded methods can be published

Delphi Compiler Error

E2266 Only one of a set of overloaded methods can be published

Reason for the Error & Solution

Only one member of a set of overloaded functions may be published because the RTTI generated for procedures only contains the name.

(*$M+*)
(*$APPTYPE CONSOLE*)
program Produce;
type
  Base = class
  published
    procedure p1(a : integer); overload;
    procedure p1(a : boolean); overload;
  end;

  Extended = class (Base)
    procedure e1(a : integer); overload;
    procedure e1(a : boolean); overload;
  end;

  procedure Base.p1(a : integer);
  begin
  end;

  procedure Base.p1(a : boolean);
  begin
  end;

  procedure Extended.e1(a : integer);
  begin
  end;

  procedure Extended.e1(a : boolean);
  begin
  end;

end.


In the example shown here, both overloaded p1 functions are contained in a published section, which is not allowed.

Further, since the $M+ state is used, the Extended class starts with published visibility, thus the error will also appear for this class also.

(*$M+*)
(*$APPTYPE CONSOLE*)
program Solve;
type
  Base = class
  public
    procedure p1(a : integer); overload;
  published
    procedure p1(a : boolean); overload;
  end;

  Extended = class (Base)
  public
    procedure e1(a : integer); overload;
    procedure e1(a : boolean); overload;
  end;

  procedure Base.p1(a : integer);
  begin
  end;

  procedure Base.p1(a : boolean);
  begin
  end;

  procedure Extended.e1(a : integer);
  begin
  end;

  procedure Extended.e1(a : boolean);
  begin
  end;

end.


The solution here is to ensure that no more than one member of a set of overloaded function appears in a published section. The easiest way to achieve this is to change the visibility to public, protected or private; whichever is most appropriate.

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