List index out of bounds error
Posted on 1999-09-03
I'm trying to use the following code to parse through a TStringList and check each string to see if it contains a particular substring. If it does, then I want that string removed from the TStringList.
Count := AddList.Count;
for X := 0 to Count - 1 do
if Pos(HomeDrive, Addlist.Strings[X]) <> 0 then
When it hits the last element in the TStringList, I get the "List index out of bounds (X)" (where X is the last string in the list). It doesn't matter how many strings are present, or whether or not any or all of them are to be removed. If I just tell it to ShowMessage and not delete the strings as it parses the list it works fine, but when I instruct it to delete the string it then blows up.
I'm stuck. Any help would be appreciated.