Delphi Error – E2009 Incompatible types – ‘%s’

Delphi Compiler Error

E2009 Incompatible types – ‘%s’

Reason for the Error & Solution

The compiler has detected a difference between the declaration and use of a procedure.

program Produce;

  type
    ProcedureParm0 = procedure; stdcall;
    ProcedureParm1 = procedure(VAR x : Integer);

  procedure WrongConvention; register;
  begin
  end;

  procedure WrongParms(x, y, z : Integer);
  begin
  end;

  procedure TakesParm0(p : ProcedureParm0);
  begin
  end;

  procedure TakesParm1(p : ProcedureParm1);
  begin
  end;

begin
  TakesParm0(WrongConvention);
  TakesParm1(WrongParms);
end.

The call of ‘TakesParm0’ will elicit an error because the type ‘ProcedureParm0’ expects a ‘stdcall’ procedure, whereas ‘WrongConvention’ is declared with the ‘register’ calling convention. Similarly, the call of ‘TakesParm1’ will fail because the parameter lists do not match.

program Solve;

  type
    ProcedureParm0 = procedure; stdcall;
    ProcedureParm1 = procedure(VAR x : Integer);

  procedure RightConvention; stdcall;
  begin
  end;

  procedure RightParms(VAR x : Integer);
  begin
  end;

  procedure TakesParm0(p : ProcedureParm0);
  begin
  end;

  procedure TakesParm1(p : ProcedureParm1);
  begin
  end;

begin
  TakesParm0(RightConvention);
  TakesParm1(RightParms);
end.

The solution to both of these problems is to ensure that the calling convention or the parameter lists matches the declaration.

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