Archive for November, 2009

DestroyHandle and Delphi 2007

Wednesday, November 18th, 2009

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. :(

How to Create an Active Form in Delphi 2007

Wednesday, November 11th, 2009

I spent a couple of hours frustrating myself today trying to remember how to create an active form using Delphi 2007.  I knew that I had done it before, but do you think I could remember how?  No way! So to avoid future frustrations I decided to write it down.

Before you can create an active form, you first need to create a new project by selection File | New | Other | Activex | Activex Library.  Once that step is done, you can create the active form by selecting File | New | Other | Activex | Active Form.  Leaving out the first step will cause you to slowly go crazy while you search all of the Delphi project item categories for the active form wizard without finding it.