Monday 31 August 2020

Delphi bug: Invalid Window Handle Error 1400

My program developed a bug where sometimes on exit an access violation error and invalid window handle error would appear.

invalidhandle

The bug wasn’t totally random but occurred when some sectors in a grid were selected but not when other sectors in the same grid were selected. The grid was an image.

The program uses several TMemo components to display information pertaining to the sector selected and the number of lines displayed in each TMemo varies for each sector.

By trial and error it was found that the bug was caused by appending strings to a TMemo which happened to be the seventh and last TMemo on the form.

I am not skilled enough to get to the bottom of the cause but it seems the bug was caused by the number of lines appended to the TMemo and the length of the lines. No exceptions were raised here though.

Fewer lines no problem. More lines no problem. Shorter lines no problem.

I don’t know why but a TMemo.Lines.Text length between 284 and 308 caused the error.

I fixed the error by ensuring the text length was not between these two values.

Using Delphi Community Edition 10.2.3 on Windows 10.

No comments:

Post a Comment