我在Delphi中发布了一个关于在方法声明中修复错误的问题,但在修复它之后,在编译时弹出了另一个错误,并且它说项目project1.exe引发异常类EStringListError,消息'list index out of bounds(0) '.当我按下继续它不工作,但当我按下它在代码上闪烁 neraz:=true;
这是我的代码如下
Procedure Reload;
var
i:integer;
begin
form1.ListBox1.Clear;
form1.ListBox2.Clear;
if neraz then
HD;
neraz:=true;//..................here
form1.Label3.Caption:='free: '+inttostr(vs*32)+' byte'+#10#13+'cluster size = 32 bytes';
i:=TABLE[nk1].nach;
KolP1:=0; KolP2:=0;
while (FAT[i]<>1024) do begin
if TABLE[fat[i]].tip then begin
form1.ListBox1.Items.Add('dir>'+TABLE[fat[i]].name);
inc(kolP1);
end
else
if TABLE[fat[i]].format='txt' then
form1.ListBox1.Items.Add('f_text> '+TABLE[fat[i]].name+'.'+TABLE[fat[i]].format)
else
form1.ListBox1.Items.Add('f_bin> '+TABLE[fat[i]].name+'.'+TABLE[fat[i]].format);
if (fat[i]<>0) then
i:=fat[i];
end;
i:=TABLE[nk2].nach;
while (FAT[i]<>1024) do begin
if TABLE[FAT[i]].tip then begin
form1.ListBox2.Items.Add('dir>'+TABLE[fat[i]].name);
inc(kolP2)
end
else
if TABLE[fat[i]].format='txt' then
form1.ListBox2.Items.Add('f_text> '+TABLE[fat[i]].name+'.'+TABLE[fat[i]].format)
else
form1.ListBox2.Items.Add('f_bin> '+TABLE[fat[i]].name+'.'+TABLE[fat[i]].format);
if (fat[i]<>0) then
i:=fat[i];
end;
vfail;
end;
procedure HD;
var
i: integer;
begin
for i := 0 to 49 do begin
with form2.ListView1.Items[i] do begin
SubItems[0] := TABLE[i].name;
SubItems[1] := TABLE[i].format;
if TABLE[i].tip then
SubItems[2] := 'folder'
else
SubItems[2] := 'file';
SubItems[3] := IntToStr(TABLE[i].nach);
SubItems[4] := IntToStr(TABLE[i].razmer);
end;
form2.ListView2.Items[i].SubItems[0] := IntToStr(fat[i]);
end;
end;
Run Code Online (Sandbox Code Playgroud)
EStringListError当您尝试访问TStrings空的实例的成员时,异常类将错误列表索引引出超出范围(0).最有可能的候选者是SubItems列表项的属性.
你似乎陷入了一个非常普遍的陷阱.虽然您已为列表视图创建了列,但您还需要SubItems为每个列表项填写列表.一个简单的解决方案是修改HD如下:
with form2.ListView1.Items[i] do begin
while SubItems.Count<5 do
SubItems.Add('');
SubItems[0] := ...
Run Code Online (Sandbox Code Playgroud)
虽然在创建列表项的同时添加子项实际上可能更好.但是我没有显示代码,因为你没有包含填充列表的程序部分.
| 归档时间: |
|
| 查看次数: |
10674 次 |
| 最近记录: |