Delphi 函数如何引用数组;

2024-12-26 15:46:39
推荐回答(3个)
回答1:

添加这个数组的单元名就可以了。

在实现代码后面
uses
xxxx;
然后即可引用,看基础吧。这些都是小事

回答2:

unit Unit1;
interface
uses
forms, SysUtils, StdCtrls, Classes, Controls;
type
MyRecord = record
a:Integer;
end;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MyArray:array[0..1] of MyRecord;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Unit2;
procedure TForm1.Button1Click(Sender: TObject);
begin
InitArray();
edit1.Text:=inttostr(MyArray[0].a);
edit2.Text:=inttostr(MyArray[1].a);
end;
end.
----------------------------------------------------------------------------------------------

unit Unit2;
interface
Procedure InitArray();
implementation
uses Unit1;
Procedure InitArray();
begin
Form1.MyArray[0].a:=1;
Form1.MyArray[1].a:=2;
end;
end.

回答3:

如访问MyArray[0]可以:
TForm1.MyArray[0]