If deleting items from a list you should count backwards. for tval := Memo1.Lines.Count - 1 downto 0 do
JED ================================================================================================= Hi all. I am having a problem with tmemo in that if I delete one item in the loop below the memo is stuffed afterwards. But in the second example memo is OK. Any tips?? Logically, memo count is adjusted after one item deleted but tval is inc'd for next. Tval needs to be dec'd prior to next count (I think) but you cant do that! for tval := 0 to memo1.Lines.Count - 1 do begin with memo1.Lines do begin if (directoryexists(strings[tval])) then //its DEFINITELY a directory if not dirhasfile(strings[tval]) then delete(tval) else strings[tval] := IncludeTrailingBackSlash(strings[tval]) + '*.*'; end; end; This works: counter:integer; for tval := 0 to memo1.Lines.Count - 1 do begin with memo1.Lines do begin if (directoryexists(strings[tval])) then //its DEFINITELY a directory if not dirhasfile(strings[tval]) then counter:=tval else strings[tval] := IncludeTrailingBackSlash(strings[tval]) + '*.*'; end; end; memo1.lines.delete(counter); //FINE FOR ONE INSTANCE ONLY! --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the [EMAIL PROTECTED] --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/