How to free dynamic TImages... tricky question.
Posted on 1998-10-13
I create 10 to 20 TImages when a certain button is pressed. I fill in the tag of each image with a certain value. I load a bitmap into the image. Most importantly I assign a one predefined procedure to the OnClick of each TImage.
This predefined procedure performs some loading of stuff in the program. As soon as the procedure is completed I want to free the TImages... I don't want them hanging around using precious resources (my program is already relatively resource hungry). Unfortunately I can't free the TImages in the procedure that is attached to the TImages OnClick event, as it causes an AccessViolation when the procedure tries to end... since the TImages no longer exist, the fucntion no longer has the reference back to the objects it was expecting.
How do I free these TImages?? Is there any way to call a procedure from the OnClick procedure that would be guarenteed to execute after the OnClick procedure is finished? I thought of using a TTimer, but this just seems to kludgy. There has got to be a better way.