Autor Beitrag
Moritz M.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1672



BeitragVerfasst: Sa 08.03.03 09:19 
Hi

Gibt es eine Prozedur um in einer TListBox doppelt vorhandene Einträge zu entfernen? Oder gibt es eine Variable, die man setzt kann, dass dann ein Eintrag, der schon vorhanden ist, gar nicht hinzugefügt wird? Von sowas hab ich nämlich mal gehört.

Thx
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 08.03.03 13:33 
Onz hat folgendes geschrieben:
Hi

Gibt es eine Prozedur um in einer TListBox doppelt vorhandene Einträge zu entfernen?

meines wissens nach nicht
Zitat:
Oder gibt es eine Variable, die man setzt kann, dass dann ein Eintrag, der schon vorhanden ist, gar nicht hinzugefügt wird? Von sowas hab ich nämlich mal gehört.


ja nennt sich duplicates und ist entweder bei den Listbox oder bei Items->TStrings drin. (Hab grad kein aktuelles Delphi zu hand, kann nicht nachguggn)

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Spike
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 69
Erhaltene Danke: 1



BeitragVerfasst: Sa 08.03.03 13:46 
Es gibt die Eigenschaft Duplicates := DupIgnore
Allerdings für TStringList. Hat nur Auswirkung wenn Sorted true ist.

Für diesen Beitrag haben gedankt: Jakane
Moritz M. Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1672



BeitragVerfasst: Sa 08.03.03 19:26 
Das geht irgendwie nicht... :cry:
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 08.03.03 19:53 
ok, stringlist wars, sorry


wenn du den Umweg über eine Stringlist nicht gehen willst, nutze indexof
Ich bin auch ziemlich sicher, daß das mit duplicate vor kurzem hier im Forum behandelt wurde, such mal
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
procedure TForm1.Button1Click(Sender: TObject);
//Item nur hinzufügen, wenn es noch nicht in Liste ist
begin
  if ListBox1.Items.indexof(edit1.text)=-1 then
    listbox1.items.add(edit1.text);
end;

procedure TForm1.Button2Click(Sender: TObject);
//alle doppelten Items in der Listbox löschen
Var i:integer;
    S:string;
begin
  with listbox1 do
    begin
     i:=items.count-1; //Listbox vom Ende durchgehen
     while i>=0 do
       begin
         s:=items[i];
         while items.indexof(s)<>i do
           begin
             items.Delete(items.indexof(s));
             dec(i);
           end;
         dec(i);//nächstes item
       end;
    end;
end;

ähh, hau mich nicht, wenn das zweite nicht auf Anhieb klappt, ist mir grad so eingefallen

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)