Recent

Author Topic: ive hit a major  (Read 5711 times)

cazzajay

  • Jr. Member
  • **
  • Posts: 94
ive hit a major
« on: August 06, 2009, 05:08:38 pm »
stumbling block!  :'(

in my program, the user clicks on a tlistbox that may (or may not) be populated with items.  the program then runs various tasks based on the selected item in the listbox.

if the listbox is blank, or if the user clicks outside the items (i.e. in white space), i get an out of bounds error with the kill/corrupt options.

the error seems to be inevitable, is there any way of changing the text in the errormessage to say something more friendly like "please only click on items" or even to just silently "ignore" the fact it is out of bounds altogether and do nothing at all if the user clicks on a non-item???

i've tried changing it to dblclick but that doesn't force the user to highlight and click on an item.

im at a complete loss as to this one.
Windows XP 32 bit / Lazarus 1.0.6 / FPC 2.6.0

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12024
  • Debugger - SynEdit - and more
    • wiki
Re: ive hit a major
« Reply #1 on: August 06, 2009, 05:18:36 pm »
There is a lot of info missing, in order to see what your issue is.

Assuming you have not recompiled lazarus/the LCL with rangececks enabled, then the exception is in your code.

You probably have an OnClick or similar handler.
One way is to encapsulate the whole code inside in a try except end block

 procedure TForm1.ListBox1Click(Sender: TObject);
 begin
   try
    // your code
   except
    // handle errors
   end;
 end;

Then again are you using ItemIndex? simply check if it is not negative
  if Listbox.itemindex<0 then exit; // or display error or....

If the error is not in your code, provide which version of Lazarus you use and a sample how to trigger it.

cazzajay

  • Jr. Member
  • **
  • Posts: 94
Re: ive hit a major
« Reply #2 on: August 06, 2009, 05:37:46 pm »
the "itemindex < 0" worked!  :D

i can't believe i didnt think of that one!
 :-[

fyi i was using listbox1.items[listbox1.itemindex] to get the currently selected item.  i'm not too comfortable with exceptions just yet, so this way seemed best.  im using 0.9.26.2 on vista 32 bit (running in bootcamp on a macbook  :D )
Windows XP 32 bit / Lazarus 1.0.6 / FPC 2.6.0

 

TinyPortal © 2005-2018