DestroyHandle and Delphi 2007

Back in the good old days, when Windows 98 was king of the desktop, it didn’t matter how much memory your system had there was a hard limit on the number of resources (like window handles) that could be active at any one time.  This caused me problems with some of my larger applications.  They kept maxing out the active resources.

To get around this problem, there as a little trick that you could use with Delphi 5 to free the resources used by a window that was not visible.  To free the resources you used TWinControl.DestroyHandle to free the handles for the window that was about to be hidden and all of its child windows.  So this code went into all of my larger programs 10 or 11 years ago and everything was golden.  I even forgot that I had put the resource saving code into the programs.

So, skip forward 10 or 11 years and I am merrily porting my programs from Delphi 5 to Delphi 2007.  All of a sudden I start to encounter strange problems.  For example, I had a ComboBox on a page in a page control.  If I left the page containing the ComboBox and then returned to that page, the ComboBox’s drop down list was cleared.  I spent many hours debugging this to absolutely no avail. Until I finally stumbled across my little resource saving fiddle.  I removed that code from the program and now everything works as it should.  Fortunately, since Windows 98 is long dead (or should be) this code is no longer necessary so removing it isn’t going to cause me any heartache (I hope).

Codegear (now Embarcadero) obviously changed something in the implementation of the DestroyHandle method.  No wonder I am sick of programming. :(

Leave a Reply