[lazarus] Order of destruction in TCustomListBox
Vincent Snijders
vslist at zonnet.nl
Sat Dec 13 11:38:04 EST 2003
On Fri, 12 Dec 2003 17:54:41 +0100
Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
> On Fri, 12 Dec 2003 17:02:56 +0100 Vincent Snijders
> <vslist at zonnet.nl> wrote:
>
> > Hi,
> >
> > The destructor of TCustomListBox is:
> > destructor TCustomListBox.Destroy;
> > begin
> > FreeAndNil(FCanvas);
> > inherited Destroy;
> > FreeAndNil(FItems);
> > end;
> >
> > As I am implementing the TCheckListBox items collection for win32, I
> > would like to access the listbox handle, while in the destructor of
> > the items collection. Unfortunately the window (+ items + item data
> > stored in it) are lost before the destructor for the items
> > collection is called.
> >
> > Therefore I want to ask, if it is possible to change to destructor
> > to: destructor TCustomListBox.Destroy;
> > begin
> > FreeAndNil(FCanvas);
> > FreeAndNil(FItems);
> > inherited Destroy;
> > end;
> >
> > If this is not possible, I will probably find another way to close
> > the checklistbox without memory leaks, but changing this is easier
> > for me.
>
> What about:
>
> destructor TCustomListBox.Destroy;
> begin
> Destroying;
> DestroyWnd;
> FreeAndNil(FCanvas);
> inherited Destroy;
> FreeAndNil(FItems);
> end;
>
> The Destroying; can accelerate the destruction and DestroyWnd will
> clean up. Maybe such things should be added to more controls.
>
> I think, we should keep fItems like the VCL until after the "inherited
> Destroy;".
OK,
Some further investigation with the destructor as I proposed showed that
listbox handle is already invalid before calling the inherited destroy.
What happened I am not sure and I plan on doing things a little
different, so I don't any changes to the the TCustomListBox destructor.
Regards,
Vincent.
More information about the Lazarus
mailing list