Problem freeing components with .free



Delphi help says:

FREE Method

"Never explicitly free a component within one of its own event
handlers or the event handler of a component it owns or contains. For
example, don't free a button, or the form that owns the button, in its
OnClick event handler."

----------------------------------------------------------------------------------------

In my form I have a image listing section, a save button and a
SaveImages() function associated with save button's onclick handler.

SaveImages() do some saving operations and then destroys (with .free
method) images and the save button. As said in delphi warning, i am
getting access violation after freeing the save button.
I tried to make a SaveButtonHandler for onclick handler and inside it
calling the SaveImages function but seems it has the same effect.

I created a threaded timer and activated it on savebuttonhandler and
then called saveimages() on timer event. This worked great but lead me
to another programming limitations (because of a isolated thread
process).

So, does anybody know any workaround for using .free on this
situation, without using timers?

.


Quantcast