Delphi – E2008 Incompatible types

When the compiler expects two types to be compatible (that is, highly similar), yet they turn out to be different, this error message appears. This error can arise in a variety of situations, such as when a read or write clause in a property refers to a method with a parameter list that does not match the property, or when a parameter to a standard procedure or function is of the wrong type.

This issue can also happen if two units declare the same type name. When a parameter of the same-named type is supplied to a method from an imported unit and a variable of the same-named type is passed to that procedure, an error may result.

unit unit1;
interface
  type
    ExportedType = (alpha, beta, gamma);

implementation
begin
end.

unit unit2;
interface
  type
    ExportedType = (alpha, beta, gamma);

  procedure ExportedProcedure(v : ExportedType);

implementation
  procedure ExportedProcedure(v : ExportedType);
  begin
  end;

begin
end.

program Produce;
uses unit1, unit2;

var
  A: array [0..9] of char;
  I: Integer;
  V : ExportedType;
begin
  ExportedProcedure(v);
  I:= Hi(A);
end.

The default function Hi requires a parameter of type Integer or Word, but we gave it to it as an array. V is actually of type unit1 in the call to ExportedProcedure. Due to the fact that unit1 is imported before unit2, an error will arise.

unit unit1;
interface
  type
    ExportedType = (alpha, beta, gamma);

implementation
begin
end.

unit unit2;
interface
  type
    ExportedType = (alpha, beta, gamma);

  procedure ExportedProcedure(v : ExportedType);

implementation
  procedure ExportedProcedure(v : ExportedType);
  begin
  end;

begin
end.

program Solve;
uses unit1, unit2;
var
  A: array [0..9] of char;
  I: Integer;
  V : unit2.ExportedType;
begin
  ExportedProcedure(v);
  I:= High(A);
end.

We intended to use the regular function High rather than Hi. There are two alternatives for the ExportedProcedure call. To begin, you could change the order of the uses clause, although this could result in similar issues. A more reliable option is to completely qualify the type name with the unit that defined the desired type, like in the case of V above.