Autor Beitrag
lkz633
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 136

WinXP, Suse Linux 8.2 (unter VMWare)
D7 Prof, K3 Prof
BeitragVerfasst: Fr 16.05.03 17:41 
Hallo,

ich habe folgenden code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:= 0 to stringlist.count-1 do begin
  if blablabala then
    stringlist.delete(i)
end


Dann gibt es natuerlich eine Zugriffsverletzung.
Auch mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
index:= stringlist.count-1;
for i:= 0 to index do begin
  if blablabala then begin
    stringlist.delete(i);
    index := index-1;
end

geht es nicht.

Wie loese ich das Problem geschickt ?

Gruss und Dank
lkz633
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 16.05.03 18:01 
Du lässt den Index ganz einfach von oben loslaufen und wirst immer kleiner. Also so:

ausblenden Delphi-Quelltext
1:
for i:=stringlist.count-1 downto 0 do					


MfG,
Peter

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
lkz633 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 136

WinXP, Suse Linux 8.2 (unter VMWare)
D7 Prof, K3 Prof
BeitragVerfasst: Fr 16.05.03 19:46 
Hallo,

herzlichen Dank !!!

Aber da haette ich ja auch selber draufkommen koennen :-)

Gruss lkz633