繁体   English   中英

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 错误] D8.pas(130): E2010 不兼容的类型:'Darbas.Tmas' 和 'D8.Tmas'

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

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

你需要定义你的类型

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

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

例如,您可以选择在Darbas定义它。 然后从D8删除类型定义,并uses您已经这样做的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部分的Darbas内容现在都将在D8可见,包括Ilgis常数和Tmas类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM