2012-01-08 104 views
2

我发布了一个问题修复了Delphi中的窗体中的方法声明中的错误,但是在修复了编译时弹出的另一个错误,并且它的项目project1.exe引发了异常类EStringListError有消息“列表索引越界(0)”。当我按下继续其不工作,但是当我按下打破代码neraz:=true; 其闪烁,这是我下面列表索引越界(0)

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; 
+2

你的错误是'高清'。 – 2012-01-08 15:52:10

+0

什么是'HD'? – 2012-01-08 15:52:49

+4

你的代码是否真的格式化了?如果是这样,那么你迫切需要学习如何正确地缩进你的代码。尤其是因为您正在混合单个语句和复合语句块。这使得人生在最好的时代变得艰难,但是没有缩进纪律,你的代码是不可维护的。 – 2012-01-08 15:56:06

回答

5

代码的异常类EStringListError引发错误尝试访问空的TStrings实例的成员时,列表索引超出边界(0)。最可能的候选对象是列表项的SubItems属性。

你似乎陷入了一个相当普遍的陷阱。虽然您已为列表视图创建了列,但您还需要填写每个列表项的SubItems列表。一个简单的解决方案是修改HD这样的:

with form2.ListView1.Items[i] do begin 
    while SubItems.Count<5 do 
    SubItems.Add(''); 
    SubItems[0] := ... 

尽管它实际上可能是更好地为您创建的列表项,同时增加了分项目。但是我没有显示代码,因为你没有包含填充列表的程序部分。

+0

你是这个人感谢它的工作 – 2012-01-08 16:48:03