Forum > General

Use of ReleaseComponent

<< < (2/2)

lainz:
What I do is:

My button click sends a notify event to the parent of my panel. The parent of my panel removes the panel, and the button as well.

No problem because it doesn't remove himself.

lucamar:

--- Quote from: lainz on May 02, 2021, 07:43:49 pm ---My button click sends a notify event to the parent of my panel. The parent of my panel removes the panel, and the button as well.
--- End quote ---

Yes, that's a good solution to prevent the possibility that the code calling the button's event handler will, on return, try to do something else with a control that isn't there anymore.

Only, instead of a notification I'd send a message, to make sure any processing (e,g, the response to the mouse click on the button) is done before an attempt to destroy anything is made. It's probably overcaution but one never knows ... :-\

valter.home:
Yes, I can actually confirm abnormal behavior.
In the TButton's OnClick event the parent's FreeAndNil call is successful but if I try to use OnMouseDown or OnMouseUp it raises Access Violation.
It doesn't seem safe, better use a notify event or message.

In any case, even the use of Application.ReleaseComponent([Parent of TButton]) would seem to work regardless of the mouse event used, perhaps because it runs at the bottom of the event queue.

Navigation

[0] Message Index

[*] Previous page

Go to full version