Panadol  (Morphine to follow if required)

Don't use a For loop use a while loop.  For loops evaluate Count only once
(when they Start), while loops perform the evaluation each time they loop.
So For loops offer better performance (less evaluation) but break if the
number of items to be iterated through changes.


Rob

Software engineer
Wild Software Ltd
Ph 03 338-1407
----- Original Message -----
From: "Alistair George" <[EMAIL PROTECTED]>
To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
Sent: Tuesday, October 29, 2002 1:50 PM
Subject: [DUG]: Headache material


> 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/
>


---------------------------------------------------------------------------
    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/

Reply via email to