delphi的list循环中怎么删除满足条件的行
我需要删除list中满足条件的行,如果在循环中直接删除,第二次循环时会报错?要怎么修改呢?
Delphi/Pascal code?var IPList:TList; i:Integer; begin for i:=0 to IPList.Count-1 do begin if '192.168.1.10'=IPList[i].Value then begin If IPList[i]<>nil then begin TDSTCPChannel(IPList[i]).Close; IPList.Delete(i) ; //删除此行,第二次循环就会报错 end; End; continue; End; End;
倒着来
for i:= iplist.count-1 downto 0