List index out of bounds whilst deleting items

前端 未结 3 1232
天涯浪人
天涯浪人 2020-12-11 07:54

I solved my problem but I need to know why this problem raised to me ?!

I write a project that load file to listBox then delete the strings one by one,

but w

3条回答
  •  攒了一身酷
    2020-12-11 08:39

    There may be situation when you DO NOT delete certain items. Then the generic approach would be

    i := 0;
    while i < ListBox3.Items.Count do
      begin
        ShowMessage(ListBox3.Items[i]);
        if  then // some condition there
          ListBox3.Items.Delete(i)
        else
          Inc(i);
       end;
    

提交回复
热议问题