首页 > 解决方案 > E2010 不兼容的类型

问题描述

我有两个单位:

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);

我确实调用procedure Ieskotiunit D8按钮单击事件:

procedure TfrmD8.btn4Click(Sender: TObject);
var
nr : Byte;
begin
  Ieskoti(A, n, nr);  //HERE I GET ERROR
end;

我确实得到了错误:

[dcc32 错误] D8.pas(130):E2010 不兼容的类型:“Darbas.Tmas”和“D8.Tmas”

标签: delphidelphi-10.2-tokyo

解决方案


是的,这就是 Delphi 的类型系统的工作原理。

如果您在两个不同的位置定义了两个(静态或动态)数组类型,即使它们“相同” ,它们也不会是赋值兼容的。

你需要定义你的类型

type
  Tmas = array[1..Ilgis] of Integer;

一次,然后在每次需要时引用此类型。

例如,您可以选择在Darbas. 然后从你已经做的使用子句中删除类型定义D8并包含Darbas在其中。D8uses

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;

interface部分中的所有Darbas内容现在都将在 中可见D8,包括Ilgis常量和Tmas类型。


推荐阅读