Autor Beitrag
jackie05
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 357



BeitragVerfasst: Sa 14.07.07 03:31 
Hallo,
Ich habe nach meinem Problem schon hier im Forum gesucht und leider nix passendes gefunden.
z.B. möchte ich alle Einträge löschen, die keinen 'Hello' als Items beinhaltet.
Ich habe schon viele versuche probiert und leider kam ich nie auf das richtige ergebnis.
Ich wäre euch sehr dankbar, wenn ihr mein problem lösen könnt.

MfG


Moderiert von user profile iconGausi: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Sa 14.07.2007 um 09:34
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 14.07.07 07:57 

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
jackie05 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 357



BeitragVerfasst: Sa 14.07.07 16:56 
Danke.
Ich habe das auch so gemacht gehabt, aber so wird nur dieser Eintrag gelöscht, der angegeben wurde.

ausblenden Delphi-Quelltext
1:
ComboBox1.Items.Delete(ComboBox1.Items.IndexOf('test'));					


Ich möchte aber alle Eintrage löschen, die z.B. keinen 'test' als ComboBox1.Items haben.

Edit: Sry, ich habe mir das mal genauer durchgelesen, ich werde mal mit der Schleife prüfen, solange IndexOf 0 zurück gibt, das die Einträge gelöscht werden.

MfG
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Sa 14.07.07 19:20 
Hallo,

dass würde so gehen, außer dass es nicht 0 wäre, sondern -1. Allerdings ist das ineffizient. Mach es lieber so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=ComboBox1.Items.Count-1 downto 0 do
begin
  if ComboBox1.Items[i]="test" then ComboBox1.Items[i].Delete;
end;

Eine for-to-do-Schleife würde Probleme machen, (a sich die Indexe nachm löschen verändern, von daher hier downto.

PS: Fehler von der Syntax könnten hier sein, da ich es gerade ausm Kopf mache ;).

Grüße
Heiko
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 14.07.07 20:55 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
var
 i:Integer;
begin
  for i := ComboBox1.Items.Count - 1 downto 0 do
  if ComboBox1.Items[i] <> 'Hello' then
  ComboBox1.Items.Delete(i);
end;

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)