HomeDelphiDelphi Error – E2185 Overriding automated virtual method ‘%s’ cannot specify a dispid

Delphi Error – E2185 Overriding automated virtual method ‘%s’ cannot specify a dispid

Delphi Compiler Error

E2185 Overriding automated virtual method ‘%s’ cannot specify a dispid

Reason for the Error & Solution

The dispid declared for the original virtual automated procedure declaration must be used by all overriding procedures in derived classes.

program Produce;

  type
    Base = class
    automated
      procedure Automatic; virtual; dispid 151;
    end;


    Derived = class (Base)
    automated
      procedure Automatic; override; dispid 152;
    end;

  procedure Base.Automatic;
  begin
  end;

  procedure Derived.Automatic;
  begin
  end;

begin
end.

The overriding declaration of Base.Automatic, in Derived (Derived.Automatic) erroneously attempts to define another dispid for the procedure.

program Solve;

  type
    Base = class
    automated
      procedure Automatic; virtual; dispid 151;
    end;


    Derived = class (Base)
    automated
      procedure Automatic; override;
    end;

  procedure Base.Automatic;
  begin
  end;

  procedure Derived.Automatic;
  begin
  end;

begin
end.

By removing the offending dispid clause, the program will now compile.

Share:

Leave a Reply

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