Autor Beitrag
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Fr 24.06.05 23:45 
Hi
Ich hab eine sehr banale Frage. :(
Ich versuche jede zweite Zeile aus einer StringList zu löschen doch alle Versuche scheiterten bisher. :?
Wie man eine Zeile aus einer StringList löscht weis ich: StringList1.Delete(index);
Aber wie kann ich das möglichst kompakt in eine Schleife einbauen? Was soll ich überhaupt für eine Schleife nehmen? :gruebel:
Coder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Fr 24.06.05 23:53 
Habs jetzt hingegriegt. War gaaanz einfach! :lol:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
  i := 0;
  while i < StringList1.Count-1 do
  begin
    StringList1.Delete(i);
    inc(i,2);
  end;

Trotzdem Danke! :D


Wow, mein 500. Beitrag... ich sollte mich eigentlich schämen ... :mrgreen: :lol:
Phantom1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: Sa 25.06.05 07:44 
Es ist dir vieleicht schon aufgefallen, aber so funktioniert dein Code nicht. Du musst rückwärts du die liste gehen und jedes 2te element löschen.

zb so hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
  i:=sl.Count-1;
  if not odd(i) then
    dec(i);
  while i>=0 do begin
    sl.Delete(i);
    dec(i,2);
  end;


mfg
Phantom1
Coder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: So 26.06.05 00:41 
Komisch, bei mir funktioniert es bestens. :gruebel:

Trotzdem Danke! :D