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

x
?
Solved

List index out of bounds error

Posted on 1999-09-03
3
Medium Priority
?
428 Views
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
    AddList.Delete(X);

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.
0
Comment
Question by:Orca
[X]
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
3 Comments
 
LVL 27

Accepted Solution

by:
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
    AddList.Delete(X);

meikl ;-)
0
 

Author Comment

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

0
 
LVL 1

Expert Comment

by:Moondancer
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.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0

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: https://www.percona.com/resources/we…
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