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.