index out of bounds(-1)请教(0分)

  • 主题发起人 主题发起人 sandy2002
  • 开始时间 开始时间
S

sandy2002

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在用的是flatlistbox1控件在以下程序中出现了一个问题:
代码如下:
procedure TForm1.FlatListBox1Click(Sender: TObject);
begin
flatlistbox1.Items.Delete(flatlistbox1.ItemIndex);
end;
这个答案是flatlistbox1中items内容为空时出现.
请大家指教
 
procedure TForm1.FlatListBox1Click(Sender: TObject);
begin
if flatlistbox1.ItemIndex>0 then
flatlistbox1.Items.Delete(flatlistbox1.ItemIndex);
end;
 
这样好像不行了,我把开发的全部源代码给你,你看如何解决了:
procedure TOA_Main.FlatListBox1Click(Sender: TObject);
var
a:string;
begin
if (flatlistbox1.Items.Count>0) and (flatlistbox1.Selected[flatlistbox1.ItemIndex]) then
begin
a:= FlatListBox1.Items.strings[flatlistbox1.ItemIndex];
flatlistbox1.Items.Delete(flatlistbox1.ItemIndex); 是这一行出错了,也许是没有内容时就无法删除了,
end;
end;
在这个列表框有内容,但是在点击时,在没有内容的地方点击, 会出现:index out of bounds(索引号)这样的错误请指教.

 
to sanday2002
我试了试没有什么问题啊。在del6。0下通过。你看看是不是别什么原因 啊。
a:= FlatListBox1.Items.strings[flatlistbox1.ItemIndex]是不是少了个‘;’
 
哼,看看flatlistbox1.ItemIndex的值。
 
接受答案了.
 
后退
顶部