E2010 不兼容类型
E2010 Incompatible types
我有两个单位:
unit D8;
interface
uses Darbas;
const
Ilgis = 100;
type
Tmas = array[1..Ilgis] of integer;
和
unit Darbas;
interface
const
Ilgis = 100;
type
Tmas = array[1..Ilgis] of integer;
procedure Ieskoti(X:Tmas; m:byte; var nr:byte);
我确实在 unit D8
按钮点击事件中调用了 procedure Ieskoti
:
procedure TfrmD8.btn4Click(Sender: TObject);
var
nr : Byte;
begin
Ieskoti(A, n, nr); //HERE I GET ERROR
end;
我确实收到错误:
[dcc32 Error] D8.pas(130): E2010 Incompatible types: 'Darbas.Tmas' and
'D8.Tmas'
是的,这就是 Delphi 类型系统的工作方式。
如果您在两个不同的地方定义两个(静态或动态)数组类型,它们将不赋值兼容,即使它们是“相同的”。
你需要定义你的类型
type
Tmas = array[1..Ilgis] of Integer;
一次以后每次需要的时候都参考这个类型
例如,您可以选择在Darbas
中定义。然后从 D8
中删除类型定义,而是使用 uses
子句将 Darbas
包含在 D8
中,您已经这样做了。
unit Darbas;
interface
const
Ilgis = 100;
type
Tmas = array[1..Ilgis] of Integer;
procedure Ieskoti(X: Tmas; m: Byte; var nr: Byte);
和
unit D8;
interface
uses Darbas;
Darbas
的 interface
部分中的所有内容现在都将在 D8
中可见,包括 Ilgis
常量和 Tmas
类型。
我有两个单位:
unit D8;
interface
uses Darbas;
const
Ilgis = 100;
type
Tmas = array[1..Ilgis] of integer;
和
unit Darbas;
interface
const
Ilgis = 100;
type
Tmas = array[1..Ilgis] of integer;
procedure Ieskoti(X:Tmas; m:byte; var nr:byte);
我确实在 unit D8
按钮点击事件中调用了 procedure Ieskoti
:
procedure TfrmD8.btn4Click(Sender: TObject);
var
nr : Byte;
begin
Ieskoti(A, n, nr); //HERE I GET ERROR
end;
我确实收到错误:
[dcc32 Error] D8.pas(130): E2010 Incompatible types: 'Darbas.Tmas' and 'D8.Tmas'
是的,这就是 Delphi 类型系统的工作方式。
如果您在两个不同的地方定义两个(静态或动态)数组类型,它们将不赋值兼容,即使它们是“相同的”。
你需要定义你的类型
type
Tmas = array[1..Ilgis] of Integer;
一次以后每次需要的时候都参考这个类型
例如,您可以选择在Darbas
中定义。然后从 D8
中删除类型定义,而是使用 uses
子句将 Darbas
包含在 D8
中,您已经这样做了。
unit Darbas;
interface
const
Ilgis = 100;
type
Tmas = array[1..Ilgis] of Integer;
procedure Ieskoti(X: Tmas; m: Byte; var nr: Byte);
和
unit D8;
interface
uses Darbas;
Darbas
的 interface
部分中的所有内容现在都将在 D8
中可见,包括 Ilgis
常量和 Tmas
类型。