Fórum List index out of bounds(6) - o que é ? #230873
08/05/2004
0
estou efetuando um sorteio randomico e quando eu efetuo o primeiro sorteio otimo e preeche sem problemas, mas quando executo um segundo sorteio ele apresenta o erro
[b:a5465b4b67]LIst Index out of bounds[/b:a5465b4b67]
Gostaria de saber mais sobre o erro para poder sanar...
Abaixo codigo fonte
[b:a5465b4b67]procedure TFrmGrupos.DoisGrupos3;
begin
If (CabecaA.Caption=´´) and (CabecaB.Caption=´´) then
begin
CabecaA.Caption:=ListBox2.Items[0];
Label5.Caption:=ListBox2.Items[1];
Label6.Caption:=ListBox2.Items[2];
Label7.Caption:=ListBox2.Items[3];
CabecaB.Caption:=ListBox2.Items[4];
Label8.Caption:=ListBox2.Items[5];
Label9.Caption:=ListBox2.Items[6];
Label10.Caption:=´------------x-----------´;
end
else
if (CabecaA.Caption<>´´) and (CabecaB.Caption=´´) Then
Begin
Randomize;
TotalLista := ListBox2.Items.Count;
while TotalLista <> 0 do
begin
indiceListaA := Random(Listbox2.Items.Count);
If mCidadeA=Listbox2.Items.Strings[indicelistaA] then
ListBox2.Items.Delete(indiceListaA);
Dec(TotalLista);
end;
Label5.Caption:=ListBox2.Items[0];
Label6.Caption:=ListBox2.Items[1];
Label7.Caption:=ListBox2.Items[2];
CabecaB.Caption:=ListBox2.Items[3];
Label8.Caption:=ListBox2.Items[4];
Label9.Caption:=ListBox2.Items[5];
Label10.Caption:=´------------x-----------´;
end
else
if (CabecaA.Caption<>´´) and (CabecaB.Caption<>´´) Then
Begin
Randomize;
TotalLista := ListBox2.Items.Count;
while TotalLista <> 0 do
begin
indiceListaA:=Random(Listbox2.Items.Count);
If mCidadeA=Listbox2.Items.Strings[indicelistaA] then
begin
ListBox2.Items.Delete(indiceListaA);
end;
If mCidadeB=Listbox2.Items.Strings[indicelistaA] then
begin
ListBox2.Items.Delete(indiceListaA);
end;
Dec(TotalLista);
end;
Label5.Caption:=ListBox2.Items[0];
Label6.Caption:=ListBox2.Items[1];
Label7.Caption:=ListBox2.Items[2];
Label8.Caption:=ListBox2.Items[3];
Label9.Caption:=ListBox2.Items[4];
Label10.Caption:=´------------x-----------´;
[/b:a5465b4b67] end;
end;
Obrigado
Wagner
Wagnermarrane
Curtir tópico
+ 0Posts
08/05/2004
Cebikyn
Gostei + 0
08/05/2004
Wagnermarrane
Gostei + 0
08/05/2004
Cebikyn
Label9.Caption:=ListBox2.Items[6];
O ListBox procura o item 6, mas não acha, como ele não acha, ele mostra o erro de ´List Index out of Bounds (6)´ (cuja tradução é: ´Item da lista fora dos limites (6)´, em que o limite é o número de itens na lista)
Note que vc está deletando items (método Delete), talvez a falha do código seja essa (posso estar errado, pois não verifiquei o código detalhadamente)... e como você mesmo disse, o primeiro sorteio sai correto, já o segundo não (alguns items foram deletados pelo Delete).
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)