![]() |
Alle Einträge die sich in ListBox2 befinden in ListBox1 lösc
Wie kann man alle Einträge die sich in ListBox2 befinden in ListBox1 löschen :?:
|
Re: Alle Einträge die sich in ListBox2 befinden in ListBox1
hi
Delphi-Quellcode:
meintest du sowas?
var i: Integer;
... for i := 0 to ListBox1.Items.Count - 1 do begin if ListBox2.Items.IndexOf(ListBox1.Items[i]) <> -1 then begin ListBox2.Items.Delete(ListBox2.Items.IndexOf(ListBox1.Items[i])); end; end; ist jetzt nicht getestet... mfg, fred |
Re: Alle Einträge die sich in ListBox2 befinden in ListBox1
Ja, funktioniert wenn man
Delphi-Quellcode:
in
for i := 0 to ListBox1.Items.Count - 1 do
Delphi-Quellcode:
aendert. Warum? Wurde hier schon oft besprochen ;)
for i := ListBox1.Items.Count - 1 downto 0 do
Greetz alcaeus |
Re: Alle Einträge die sich in ListBox2 befinden in ListBox1
Nein, auch der Lauf von 0...Count-1 funktioniert im o.g. Beispiel.
Die downto-Variante ist nur dann nötig, wenn auch in der ListBox1.Items-Stringliste gelöscht würde. Da AFAIK Count-1 u.U. nur am Anfang der Schleife überprüft wird (Optimierung!?) würde es zu einem Indexfehler kommen, wenn aus der entsprechende Stringliste Elemente gelöscht werden. |
Re: Alle Einträge die sich in ListBox2 befinden in ListBox1
:wall: Klar. Ist ne Gewohnheit, jede Schleife in der was geloescht wird "downto" zu machen ;)
Greetz alcaeus |
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:39 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz