Delphi Error – E2037 Declaration of ‘%s’ differs from previous declaration

Delphi Compiler Error

E2037 Declaration of ‘%s’ differs from previous declaration

Reason for the Error & Solution

This error message occurs when the declaration of a procedure, function, method, constructor or destructor differs from its previous (forward) declaration.

This error message also occurs when you try to override a virtual method, but the overriding method has a different parameter list, calling convention etc.

program Produce;

type
  MyClass = class
    procedure Proc(Inx: Integer);
    function Func: Integer;
    procedure Load(const Name: string);
    procedure Perform(Flag: Boolean);
    constructor Create;
    destructor Destroy(Msg: string); override;      (*<-- Error message here*)
    class function NewInstance: MyClass; override;  (*<-- Error message here*)
  end;

procedure MyClass.Proc(Index: Integer);             (*<-- Error message here*)
begin
end;

function MyClass.Func: Longint;                     (*<-- Error message here*)
begin
end;

procedure MyClass.Load(Name: string);               (*<-- Error message here*)
begin
end;

procedure MyClass.Perform(Flag: Boolean); cdecl;    (*<-- Error message here*)
begin
end;

procedure MyClass.Create;                           (*<-- Error message here*)
begin
end;

function MyClass.NewInstance: MyClass;              (*<-- Error message here*)
begin
end;

begin
end.

As you can see, there are a number of reasons for this error message to be issued.

program Solve;

type
  MyClass = class
    procedure Proc(Inx: Integer);
    function Func: Integer;
    procedure Load(const Name: string);
    procedure Perform(Flag: Boolean);
    constructor Create;
    destructor Destroy; override;                   (*No parameters*)
    class function NewInstance: TObject; override;  (*Result type   *)
  end;

procedure MyClass.Proc(Inx: Integer);               (*Parameter name  *)
begin
end;

function MyClass.Func: Integer;                     (*Result type  *)
begin
end;

procedure MyClass.Load(const Name: string);         (*Parameter kind  *)
begin
end;

procedure MyClass.Perform(Flag: Boolean);           (*Calling convention*)
begin
end;

constructor MyClass.Create;                         (*constructor*)
begin
end;

class function MyClass.NewInstance: TObject;        (*class function*)
begin
end;

begin
end.

You need to carefully compare the ‘previous declaration’ with the one that causes the error to determine what is different between the two.

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