Autor Beitrag
GrU3nL!nG
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 11.04.05 08:13 
Hi,

wie kann ich aus einer Listbox doppelte elemente löschen lassen?!
könnt ihr mir helfen??
MrSaint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1033
Erhaltene Danke: 1

WinXP Pro SP2
Delphi 6 Prof.
BeitragVerfasst: Mo 11.04.05 08:36 
ich kenn keine Funktion der Listbox, ich würds über ne rekursive Fnkt oder 2 ineinander geschachtelte Schleifen machen...

_________________
"people knew how to write small, efficient programs [...], a skill that has subsequently been lost"
Andrew S. Tanenbaum - Modern Operating Systems
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mo 11.04.05 08:38 
Zuweisen zu einer TStringList mit Duplicate Ignore

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
 tt := TStringList.Create;
 tt.Sorted := True;
 tt.Duplicates := dupIgnore ;
 tt.AddStrings(ListBox1.Items);
 ListBox1.Items.Clear;
 Listbox1.Items.AddStrings(tt);
 tt.Free;



EDIT: Nachträglich eingefügt :ListBox1.Items.Clear;

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.

Für diesen Beitrag haben gedankt: Jakane
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 11.04.05 08:59 
Hallo,

oder so, ohne den Umweg über eine StringList: :wink:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button1Click(Sender: TObject);
var z : integer;
    s : string;
begin
with ListBox1 do
  begin
  for z := Items.Count-1 downto 0 do     //downto sonst gibt es eine Zugriffsverletzung
    begin
    s := Items[z];
    if (Items.IndexOf(s) <> -1)          //Eintrag ist enthalten
      and (Items.IndexOf(s) <> z) then   //Eintrag ist aber nicht der aktuelle
      Items.Delete(z);
    end;
  end;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )