如何写一个用二维数组作参数的函数(100分)

  • 主题发起人 seagull007
  • 开始时间
S

seagull007

Unregistered / Unconfirmed
GUEST, unregistred user!
如何写一个用二维数组作参数的函数,最好有例子
 
还没写过。。。学习。。。
 
我记得如果用二位数组做参数
不能使用静态数组 而是使用动态数组
Type
MyArray = array of array of string;
再用 function Test(aa:MyArray):string;
 
type
s=array of array of integer;
procedure Proc(var A: s);
begin
a[0][0]:= 999;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
x: s;
begin
setlength(x,2,2);
x[0,0]:= 2;
x[0,1]:= 3;
x[1,0]:= 4;
x[1,1]:= 5;
proc(x);
self.Caption:= inttostr(x[0,0]);
end;
 
to feng08:
procedure Proc(var A: s);
begin
a[0][0]:= 999;
end;
这个过程,如是我想把这个数组打出来,该如何写哦,
function test(A:s):String;
var i,j:integer;
str:String;
begin
str := '';
for i:= LOW(arr) to Higt(arr)do
begin
for j:=LOW(arr) to hight(arr)do
begin
str := str + IntToStr(arr[j]);
showmessage('数组为:'+str);
end;
end;
result := str;
end;
这样写不行,要报错,该咋写哦
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
s =array of array of integer;
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
function test(arr:s):String;
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
x: s;
begin
setlength(x,2,3);
x[0,0]:= 2;
x[0,1]:= 3;
x[0,2]:= 33;
x[1,0]:= 4;
x[1,1]:= 5;
x[1,2]:= 55;
self.Caption:= test(x);
end;

function TForm1.test(arr:s):String;
var i,j:integer;
str:String;
begin
str := '';
for i:= 0 to 1do
begin
for j:=0 to 2do
begin
str := str +'/'+ IntToStr(arr[j]);
showmessage('数组为:'+str);
end;
end;
result := str;
end;

end.
 
顶部