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