Board index » cppbuilder » Closing Maximized MDIChild form crash
David Ta
![]() CBuilder Developer |
Mon, 16 Dec 2002 03:00:00 GMT
Closing Maximized MDIChild form crash
This took me long time to figure out. In my MDIChild form, I use a bitmap
to buffer the drawing in order to reduce flicker. So I had something like these: __fastcall TFormEditor::TFormEditor(TComponent* Owner) : TForm(Owner) { ... PBitmap = new Graphics::TBitmap(); ... Quote} { delete PBitmap; Quote} { PBitmap->Width = ClientWidth; PBitmap->Height = ClientHeight; Quote} and then closing it, the program crash. The IDE de{*word*81} cannot catch where the program crash. It took me long time to add and delete codes just to know where it crash. The problem is this. When the maximized MDIChild form is closing. The destructor will be called and free the PBitmap. However, after that the FormResize event is called??? So it will try to resize the freed PBitmap and this crash the problem. On simple test MDI application this do not crash the problem. To fix this, I add the following codes to test whether PBitmap is deleted or not: __fastcall TFormEditor::~TFormEditor() { delete PBitmap; PBitmap = NULL; Quote} { if (WindowState == wsNormal || (WindowState == wsMaximized && PBitmap != NULL)) { PBitmap->Width = ClientWidth; PBitmap->Height = ClientHeight; } Quote} david_s_...@hotmail.com |