Freeing the item doesnt remove it from the list so I dont think the count property will change ...
Patrick > Ross Levis wrote: >> Don't use While if you don't need to. A For loop is more efficient. >> Also don't use FreeAndNil if you will not be referencing the objects >> again, which you won't be. Just use Free. You also do not need to >> dereference the objects to free the memory. >> >> var >> i : Integer; >> 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 (the While loop you criticise is way simpler IMHO): > > var > i:integer; > begin > for i:=AList.Count-1 downto 0 do > AList.Items[i].Free; > AList.Free; > inherited Destroy; > end; > > -malcolm > > _______________________________________________ > Delphi mailing list -> [email protected] > http://www.elists.org/mailman/listinfo/delphi > _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

