如何传递数组给过程或者函数

字体大小: 中小 标准 ->行高大小: 标准
问:我用procedure Proc(var A:array[1..10] of integer);怎么都不能编译通过,难道Delphi不能传递数组作为参数吗?

答:必须先用Type定义一下即可:

type

TProcArray=array[1..10] of integer;

procedure Proc(var A:TProcArray);

这样就没有问题了,而且对于动态数组也可以用上面的方法!使用动态数组的时候,有一个问题是如何遍历每一个数据项?采用类似的代码即可:

procedure Proc(var A:TProcArray);

var

i:integer;

begin

....

for i:=Low(A) to High(A) do

/// A[i]就是每一个数据项

....

end;

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/67921.html