E2037 Declaration of '%s' differs from previous declaration (Object Pascal)

From Appmethod Topics
Jump to: navigation, search

Go Up to Error and Warning Messages (Object Pascal) Index

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.