In my app I handled this (in a TListView) by writing an event handler for
the OnDeletion event. This allowed me to call the Clear method freely
without worrying about memory.

Referring to my previous code, this is the event handler:

procedure TMainForm.ServicesListDeletion(Sender: TObject; Item: TListItem);
var PLong:PLongInt;
//This event handler frees the dynamic variables allocated when the list
items were
//created. These variables are pointed to by each list item's Data property.
begin
     PLong:=PLongInt(Item.Data);
     if PLong <> nil then
        Dispose(PLong);
end;

Unfortunately there does not appear to be a similar way of handling the
deletion of items in a list or combo box.

In a TList as I noted you can simply override the destructor. Here is the
class I used in a reporting system:

TCounterList = class(TList)
[...]
   destructor Destroy; override;
   procedure Empty;
end;

and its implementation

destructor TCounterList.Destroy;
begin
        Empty;
        inherited Destroy;
end;

procedure TCounterList.Empty;
begin
        while (Count >0) do begin
                Items[Count-1].Free;
                Delete(Count-1);
        end;
end;

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Paul Lowman
> Sent: Wednesday, 11 July 2001 09:29
> To: Multiple recipients of list delphi
> Subject: Re: Listbox items (Was: Re: [DUG]: array of TStringList)
>
>
> Ross
>
> Delphi definitely does not free objects when the list is free'ed.
> So beware
> !
>
> Paul Lowman
>
> Lowman Consulting Ltd.
> Embedded Systems & Software
>
> [EMAIL PROTECTED]
>
> ------------------------------------------------------------------
> ---------
>     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