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

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

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