> > begin
> >       for i := 0 to AList.Count do
> >          AList.Items[i].Free;
> >       AList.Free;
> >       inherited Destroy;
> > end;
> 
> That For loop isn't too efficient:-) It won't work because as 
> each item  is deleted the Count property is changed.
> The following is better if you want to go that way
>
> i:integer;
> begin
>    for i:=AList.Count-1 downto 0 do
>      AList.Items[i].Free;
>    AList.Free;
>    inherited Destroy;
> end;
> 
> -malcolm


To be accurate, in the first example, nothing in the list is being deleted
and the .Count property is not changing, thus there's nothing wrong with the
concept behind the method.  However, a Delphi TList is 0-based, if I
remember correctly, so from 0 to (Count - 1) would the the correct loop.


Regards,

------------------------------------------------------------------------
 Jim Burns, <mailto:[EMAIL PROTECTED]>
   Technology Dynamics
   Pearland, Texas  USA 
   281 485-0410 / 281 813-6939




_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to