第1单元来源:
type cha = record
data1 : string;
data2 : String;
end;
type Tchadata = Array of cha;
var
A : Tchardata;
procedure TForm1.Button1Click(Sender: TObject);
begin
GetData(A);
end;
Unit2来源:
type cha = record
data1 : string;
data2 : String;
end;
type Tchadata = Array of cha;
procedure Getdata(var Data : Tchadata);
begin
end;
这是我的Delphi代码。但是遵守了...
[错误] Unit1.pas:实际和正式var参数的类型必须为
相同
为什么?
我英语不好。抱歉。
为什么不能编译?
最佳答案
虽然类型定义相同,但它们是不同的。因此,错误消息。
您应该只定义一次记录。看起来应该在Unit2
中定义它,并将其导入到Unit1
中。
单元2
unit Unit2;
interface
type
cha = record
data1 : string;
data2 : String;
end;
Tchadata = Array of cha;
procedure GetData(var Data : Tchadata);
implementation
procedure GetData(var Data : Tchadata);
begin
// Populate Data
end;
end.
单元1
unit Unit1;
interface
uses
Unit2; // imports types and the procedure
implementation
procedure Foo;
var
Data: Tchadata;
begin
GetData(Data);
end;
end.
关于function - 如何在delphi中不同调用自定义函数记录struct参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33341327/