动态数组做参数有问题吗?(100分)

  • 主题发起人 小飞龙
  • 开始时间

小飞龙

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure InitPoint(const AText :string;
var ArrPoint: array of TPoint);
begin
.......
SetLength(ArrPoint, Count)
//这里的Count是我在代码中算出来的
......
end;
在调用SetLength是有错,我把var ArrPoint: array of TPoint定义成局部变量就可以
是不是动态数组不能做参数到函数里面改动大小呢?有什么办法?
 
ype
TArrPoint = array of TPoint;

procedure InitPoint(const AText :string
var arrPoint: TArrPoint);
var
Count : Integer;
I : Integer;
begin
Count := 3;
SetLength(ArrPoint, Count)
//这里的Count是我在代码中算出来的
for i := Low(ArrPoint) to High(ArrPoint) do
begin
arrPoint.X := i *10;
arrPoint.Y := i *10;
end;
end;

procedure TForm31.Button2Click(Sender: TObject);
var
ap : TArrPoint;
i : Integer;
begin
InitPoint('hello', AP);
for I := Low(ap) to High(ap) do
begin
ShowMessage(Format('Point[%d] = (%d, %d)', [i,ap.X, ap.Y]));
end;

end;
 
type

TA = array of integer;

procedure InitPoint(var ArrPoint: TA);
begin
//Arr := ArrPoint;
SetLength(ArrPoint,100);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
ARR : TA;
begin
InitPoint(ARR);
ShowMessage(IntToStr(Length(ARR)));
end;
 
你传进来的变量是怎么定义的。
 
1,2楼的方法是对了。
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
306
import
I
顶部