Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


List index out of bounds error

Posted on 1999-09-03
Medium Priority
Last Modified: 2010-05-19
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.
Question by:Orca
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 27

Accepted Solution

kretzschmar earned 200 total points
ID: 2021807
hi orca,

just replace your code with this little change

Count := AddList.Count;
for X := Count - 1 downto 0 do
  if Pos(HomeDrive, Addlist.Strings[X]) <> 0 then

meikl ;-)

Author Comment

ID: 2021846
Thanks alot meikl for your prompt response -- that was all it took.


Expert Comment

ID: 6870148
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.
Thank you,
Moderator @ Experts Exchange

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA:…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question