可变数组的问题(200分)

  • 主题发起人 likequake3
  • 开始时间
L

likequake3

Unregistered / Unconfirmed
GUEST, unregistred user!
====================================
var
thearray:array of string;
begin
....
.....
.......
i=0;//或者i=1
thearray:=s;//s为strings类型的变量
i:=i+1;
=============================================
运行时
总在thearray:=s;出现错误
错误如下:
project project.exe raised exception class EAccessviolation with message
'access' violation at address XXXXXXXXX in medule project.exe write of a
address XXXXXX
好像是数组索引越界,怎么可能越界。这个i的变量初始赋值为0或1均出错。即将要进行
赋值操作时出的如上的错误的??
我倍感无解?希望指教!!
另外在project options 中的compiler中选上runtime error 中的range checking也不行
delphi 6企业版!
 
thearray:=s;

thearray:=s.Text;

 
SetLength(theArray, 1000); //
 
type
thearray:array of string;
var
array1:thearray;
begin
// 你的程序
end;

试一下
 
setlength(thearrary ,i)
thearray:=s;
 
动态数组使用前必须要SetLength,另外最好通过
for I:=low(thearray) to High(thearray) do
...
的方式访问。
 
好的。我加上SetLength的试试看。
 
SetLength可以通过
 
同意tseug,
动态数组都要预分配空间,不然要报地址错误。你应该是:
====================================
var
thearray:array of string;
begin
....
.....
.......
i=0;//或者i=1
setlength(Thearray,i);//分配空间
thearray:=s;//s为strings类型的变量
i:=i+1;
=============================================
 
可以了。谢谢
 
顶部