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