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:-)
The only problem with that loop is that it tries to free one more than the number of items in the list.
It won't work because as each item is deleted the Count property is changed.
Then it's a good thing none of the items are getting deleted.
The following is better if you want to go that way (the While loop you criticise is way simpler IMHO):
Simpler, perhaps, but certainly not more efficient.
-- Rob
_______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

