前面有这样的语句listbox1.ItemIndex:=0;
为什么会出现这样的错误?
list index out of bounds(-1)?

解决方案 »

  1.   


    你的ListBox没有选中任何项目,但是对项目进行操作。
      

  2.   

    前面有这样的语句listbox1.ItemIndex:=0;//这句是选中listBox的第一项,但如果listBox为空,这句不起作用。
    list index out of bounds(-1)?  索引超出范围的意思,索引不能为(-1);
      

  3.   

    同意二楼的说法,即先赋初始值:
    listbox1.item.add('项目1');
    listbox1.item.add('项目2');
    ...
    Listbox1.ItemIndex:=0;