> Message: 2
> Date: Wed, 16 Mar 2005 12:23:05 -0600
> From: Rob Kennedy <[EMAIL PROTECTED]>
> Subject: Re: Working with TList objects
> To: Borland's Delphi Discussion List <[email protected]>
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=UTF-8; format=flowed
>
> Malcolm Clark wrote:
> > 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

Hello everyone.
I use many Lists of objects
I have discovered empirically (program failed with EAccessViolation) that
the only method is

procedure Clear; override;

procedure Clear;
var
  Loop : integer
begin
  for Loop := Count - 1 downto 0 do
    TObject(List[Loop]).free;

  inherited Clear;
end;

Using a Loop counting up the first collision occurs when Loop = Count div 2

Mick


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

Reply via email to