Autor Beitrag
Hack Gott
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 409

Windows Vista
Delphi 2005 Personal, Delphi 7
BeitragVerfasst: Do 18.08.05 15:07 
Also ich hab eine Listbox mit einer nicht genau definierten Anzahl an Items. Ich hab ein Item z.B.: Hack Gott, jetzt soll mein Programm die Zeile, in der Hack Gott steht löschen. Ich habe aber keine Lust jede Zeil einzeln zu überprüfen.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 18.08.05 15:14 
Moin!

ausblenden Delphi-Quelltext
1:
ListBox1.Items.Delete(ListBox1.Items.IndexOf('Hack Gott'));					


OH durchblättern und mal ein bischen nachdenken, vor dem Posten... :wink:

cu
Narses
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Do 18.08.05 15:15 
gruß,
probier's mal so
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
ListBox.Items.Delete(ListBox.Items.IndexOf('Hack Gott'));
// aber warum hast du keien Lust jede einzelne Zeile zu überprüfen?
// IndexOf wird auch nichts anderes machen
...
var 
 i: integer;
...
for i := ListBox.Items.Count-1 downto 0 do
if ListBox.Items[i] = 'Hack Gott' then ListBox.Items.Delete(i);
// um jedes Vorkommnis zu löschen, ansonsten einfach noch ein Break hinein, 
wenn nur das erste Vorkommnis gelöscht werden soll


mfg
GSE

[edit] Mist zu langsam, aber IndexOf gibt bei Nichtvorhandensein "-1" zurück und erzeugt mit Delete dann eien Exception, also vorher besser auf "-1" prüfen.[/edit]

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)