Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi ComboBox: keine doppelten Einträge (https://www.delphipraxis.net/21757-combobox-keine-doppelten-eintraege.html)

yankee 7. Mai 2004 19:22


ComboBox: keine doppelten Einträge
 
Ich will aus einer ComboBox (mit sorted=True) alle doppelten Einmträge entfernen. Das sieht dann soi aus:

Delphi-Quellcode:
for i :=1 to VerlagcomboBox.Items.Count do
    begin
        if VerlagcomboBox.Items.Names[i] =VerlagcomboBox.Items.Names[i+1] then VerlagComboBox.Items.Delete(i);
    end;
Funzt aber nicht. Was ist falsch?

toms 7. Mai 2004 19:28

Re: ComboBox: keine doppelten Einträge
 
Hi,

Hier eine andere Variante:

Delphi-Quellcode:
var
  sl: TStringList;
begin
  sl := TStringList.Create;
  try
    with sl do
    begin
      sl.Sorted := True;
      Duplicates := dupIgnore;
      Assign(ComboBox1.Items);
    end;
    ComboBox1.Items.Assign(sl);
  finally
    sl.Free;
  end;

Markus K. 7. Mai 2004 19:29

Re: ComboBox: keine doppelten Einträge
 
Hallo yankee,
versuche es mal so.
Delphi-Quellcode:
for i :=0 to VerlagcomboBox.Items.Count-1 do
begin
     if VerlagcomboBox.Items.Names[i] =VerlagcomboBox.Items.Names[i+1]
     then VerlagComboBox.Items.Delete(i);
end;
Tschüß Markus

toms 7. Mai 2004 19:32

Re: ComboBox: keine doppelten Einträge
 
Musst noch eine DownTo-Schleife nehmen!


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:52 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz