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 when I delete listBox strings this exception raised to me!
list index out of bounds (5) !
I type this for loop to read list box and delete strings:
for i := 0 to ListBox3.Count -1 do
begin
ShowMessage(ListBox3.Items[i]);
ListBox3.items.Delete(i);
end;
and my problem solved by do a little change in for-loop statement
for i := ListBox3.Items.Count - 1 downto 0 do
begin
ShowMessage(ListBox3.Items[i]);
ListBox3.items.Delete(i);
end;
Why the first statement raised an exception, and the second one work fine ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…