Missing user interface control on tab, why does calling HandleNeeded fix it?

I had one user interface object attached to a tab, which would be absent only with a certain sequence of interaction with the program, and if it is absent, closing the program will result in an AV error and an Invalid Window Handle error. Since I was trying to find out why, I found that calling it .Handle or .HandleNeeded at the beginning would fix the problem. But this does not answer why he corrects the problem.

So, I would like to know that this is so common? Has anyone come across this weird bug? And do you know the reason?

0
delphi
source share
2 answers

If you use TabControl, Delphi only creates controls for each page when the page is needed (for speed and resource usage). Attempting to access controls on a page that has not been shown will cause problems if you do not call .HandleNeeded. A call to .HandleNeeded tells Delphi that you need a handle now and fixes the problem.

This is not a mistake, by the way. This is an intentional design solution to speed and minimize resource usage, as I mentioned above.

+3
source share

If the control was created at run time: make sure that the parent and owner of the component are installed!

+2
source share

All Articles