Autor Beitrag
AlA
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: Sa 26.04.03 20:30 
Hallo !

Ich programmiere zur zeit ein Spiel. Ich habe eine listbox in der die Spieler mit Punkten abgespeichert werden und möchte dann anhand der Position die besten 5 in Labels eintragen lassen aber es kommt ein komischer Fehler mit dem ich nicht viel anzufangen weis "Listbox index out of bounds 0"

Hier ist der Code:
ausblenden Quelltext
1:
2:
form7.label6.Caption:=form2.listbox1.Items[0];
form7.label7.Caption:=form2.listbox1.Items[1];

Bitte um Hilfe, Danke und Gruß ALA!!!!

Moderiert von user profile iconTino: Code-Tags hinzugefügt.

_________________
ala
patrick dee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: So 27.04.03 12:51 
hi

der fehler kommt wenn auf die liste zugegriffen wird aber nix drin ist.
so umgehst du dies.
ausblenden Quelltext
1:
 If ListBox1.ItemIndex = -1 then exit;					



ciao

patrick

_________________
Glauben heißt nichts wissen ...
Raphael O.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1596


VS 2013
BeitragVerfasst: So 27.04.03 16:33 
itemindex gibt IMO das markierte Item zurück...
besser wäre da items.count....
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Sa 03.05.03 22:58 
beispiel:
ausblenden Quelltext
1:
if ListBox1.items.count = 0 then Exit; // springt rauß wenn die liste leer ist					

_________________
MFG
Michael Springwald, "kann kein englisch...."