aurora
aurora

Reputation: 11

How to different call custom function record struct parameter in delphi?

Unit 1 source:

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 source:

type cha = record
 data1 : string;
 data2 : String;
end;

type Tchadata = Array of cha;

procedure Getdata(var Data : Tchadata);
begin

end;

This is my Delphi code. But complied...

[Error] Unit1.pas: Types of actual and formal var parameters must be identical

Why?

I don't well english. Sorry.
Why it can not be compiled?

Upvotes: 1

Views: 296

Answers (1)

David Heffernan
David Heffernan

Reputation: 613352

Whilst the types are defined identically, they are distinct. Hence the error message.

You should define the record exactly once. It looks like it should be defined in Unit2, and imported into Unit1.

Unit2

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.

Unit1

unit Unit1;

interface

uses
  Unit2; // imports types and the procedure

implementation

procedure Foo;
var
  Data: Tchadata;
begin
  GetData(Data);
end;

end.

Upvotes: 3

Related Questions