Answer the question
In order to leave comments, you need to log in
How to fix listerror list index out of bounds error?
There is an sListBox1 component on the form (a kind of ListBox1 in Alpha Controls).
Elements are added
there In the code, I need to iterate over all the elements of this sListBox1 . Work is in flux.sListBox1.Items.Add('..........');
procedure TMyThread.Execute;
var
i:integer;
begin
for i:=0 to form1.sListBox1.Items.Count-1 do
begin
full_filename_path:=form1.sListBox1.Items[i];
filename_name:=ExtractFileName(form1.sListBox1.Items[i]);
//.....
end;
end;
end;
Answer the question
In order to leave comments, you need to log in
The counter bounds are FOR
calculated once before the loop. If the main thread changes form1.sListBox1
, it may not be the right Items[i]
. Or check it out. Or use a loop WHILE
that checks the counter against the condition each time.
Note: The optimizer may change direction FOR
.
Tip: don't link modules.
That is, y TMyThread
must have its own TStrings
, into which you need to pass form1.sListBox1.Items
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question