Templot Club Archive 2007-2020                             

topic: 3161List index out of bounds (-1)
author remove search highlighting
 
posted: 27 Dec 2017 00:06

from:

DerekStuart
 
United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides
Hello Martin

I am getting pop up boxes marked Templot2 at the top and the message 'List index out of bounds (-1)' (inverted commas added by me).

I just ignore it and it carries on. I did find it a little while back but the window appeared and disappeared so quickly that I couldn't read it and thus couldn't report it.

If it's any help it happens when there are quite a few templates on the trackpad. This laptop is fairly iffy since the Windows 10 update a while back so it may well just be down to that.

Best wishes
Derek

posted: 27 Dec 2017 01:48

from:

Martin Wynne
 
West Of The Severn - United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides
Hello Derek,

Thanks for reporting it.

Can you remember the last thing you clicked before it happened? Without that information I am looking for a needle in a haystack.  :(

You may be interested in this:

 topic 1629

and this: 

 topic 970

and this:

 topic 1136

cheers,

Martin.

posted: 27 Dec 2017 13:09

from:

DerekStuart
 
United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides
Hello Martin

I did find one of those examples you listed- apologies, I didn't think to look further in case there were any more.

If I'm being 100% honest I can't now recall whether it happened when I went to store the control template or when I tried to lay a new one- but either way control did return to the previous template.

The programme carried on, I repeated the action without issue. I will pay more attention in the future.

NB for my own understanding for my (very basic) programming, have I understood correctly that this message is due to searching for a specific line of data (presumably the Templot file in memory/cache/page/etc?) that isn't there?

Ie I'm searching for template XYZ123 but there isn't a template matching that description in the memory?

(If I'm pushing my luck by asking technical questions, please forgive me).

Many thanks
Derek

posted: 27 Dec 2017 16:22

from:

Martin Wynne
 
West Of The Severn - United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides
DerekStuart wrote:
NB for my own understanding for my (very basic) programming, have I understood correctly that this message is due to searching for a specific line of data (presumably the Templot file in memory/cache/page/etc?) that isn't there?

Ie I'm searching for template XYZ123 but there isn't a template matching that description in the memory?

(If I'm pushing my luck by asking technical questions, please forgive me).
Hi Derek,

Not at all, it's interesting.

In Delphi and Lazarus a list is a very common construct. There are a great many lists in Templot.

Such lists are indexed starting from zero. i.e. the first item in the list is indexed [0], the second item is indexed [1], etc.

Consequently if you have a list containing 10 items, valid index values are in the range 0-9 when accessing the list. If you request a data item from the list using an index outside that range, or try to put data into the list for an item outside that range, you get the message "List index out of bounds". 

If the list is empty, the current list Count value is 0, but the current index returns the value -1 because there is no current data for index [0].

If you create a list but forget to put any data in it, or delete all the data in it, or most likely delete the last item in the list without noticing that it was the last, any subsequent attempt to access data in the list returns the message "List index out of bounds (-1)".

It's a bit more complicated than that, because you could if you wish catch the exception yourself and handle it, like this:

try
  data:=my_list.Strings[next_index];
except
  data:='no data available';
end;


In which case if the list is empty, you still get a valid result, instead of the "out of bounds" message.

Generally I prefer to do a proper test:

if (my_list.Count>0) and (next_index>=0) and (next_index<my_list.Count)
   then data:=my_list.Strings[next_index]
   else data:='no data available';


Or more typically:

if (my_list.Count<1) or (next_index<0) or (next_index>=my_list.Count)
   then begin
          ShowMessage('Something has gone wrong');
          ...
          do_something_about_it;
          ...
        end
   else data:=my_list.Strings[next_index];


For more info, see:

 http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devwin32/vptworkingwithstringlists_xml.html

cheers,

Martin.

posted: 29 Dec 2017 01:16

from:

DerekStuart
 
United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides
Hello Martin

Thanks for that explanation. I have tried some internet examples of string lists. I didn't realise that's what it was referring to.

Normally I can pick things up fairly quickly, but I must admit to finding this fairly hard going.

I shall persevere.

Thanks
Derek

posted: 29 Dec 2017 01:23

from:

Martin Wynne
 
West Of The Severn - United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides
DerekStuart wrote:
Normally I can pick things up fairly quickly, but I must admit to finding this fairly hard going.

I shall persevere.
Hi Derek,

What are you actually trying to do?

If you post a bit of code here we might find an easier way.

Generally there is a IT professional way of doing things, shown in published examples, and a "Meccano" way.

The compiler doesn't mind how inelegant your code is, it all works just the same if it delivers the right answer.  :)

regards,

Martin.

posted: 29 Dec 2017 01:55

from:

DerekStuart
 
United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides
Thanks Martin. You're a true Gent.

I'm not specifically trying to do anything at the moment- just taking sample pieces of code from the internet, seeing how they work- chopping bits out to see what stops working etc.

I did find another site after your previous reply as I tried to search what it all meant; I shall give that a go at the weekend on the desktop. I will get the hang of it. Eventually.

Thanks again not only for the info, but also the encouragement. It means a lot.
Derek

posted: 29 Dec 2017 02:05

from:

Martin Wynne
 
West Of The Severn - United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides
Hi Derek,

You may find Gary Darby's site worth a look:

 http://www.delphiforfun.org

cheers,

Martin.



Templot Club > Forums > I found a flaw > List index out of bounds (-1)
about Templot Club

Templot Companion - User Guide - A-Z Index Templot Explained for beginners Please click: important information for new members and first-time visitors.
indexing link for search engines

back to top of page


Please read this important note about copyright: Unless stated otherwise, all the files submitted to this web site are copyright and the property of the respective contributor. You are welcome to use them for your own personal non-commercial purposes, and in your messages on this web site. If you want to publish any of this material elsewhere or use it commercially, you must first obtain the owner's permission to do so.
The small print: All material submitted to this web site is the responsibility of the respective contributor. By submitting material to this web site you acknowledge that you accept full responsibility for the material submitted. The owner of this web site is not responsible for any content displayed here other than his own contributions. The owner of this web site may edit, modify or remove any content at any time without giving notice or reason. Problems with this web site? Contact webmaster@templot.com.   This web site uses cookies: click for information.  
© 2020  

Powered by UltraBB - © 2009 Data 1 Systems