form close / destroy problem

2004-01-29 10:47:37 PM
I think i had earlier posted problem in wrong section
Here it is again with a few more details
I am facing a weird problem maybe cause of 'MESSAGE_HANDLER' macro
When i close certain child forms in my application I get
EInvalidPointer Exception while attempting to destroy the form.
(child forms are created using new & destroyed using delete)
my earlier code was something like below
************** In Main Class ***************
void __fastcall MailProcessSerRec(TMessage);
MESSAGE_HANDLER( WM_Serial_Rec, TMessage, MailProcessSerRec)
#define WM_Serial_Rec (WM_USER + 100)
This was used to handle the messages received from serial comm port.
I later moved this code to another class designed to handle messages
recieved on serial comm port.
This new class is a form created in main class and lasts for lifetime
of application.
However, now i observe i get EInvalidPointer Exception when certain
child forms are being closed.
in FormClose I have Action = caFree;
I then receive a message on serial port and on processing the message
i call delete <form>for this form & i get the exception
Running the earlier version of code in debug mode I saw that on call
of child form destructor,
the above macro is executed (though call to method
'MailProcessSerRec' is not made) and then control returned to
The same happens while exiting destructor
This does not happen now with the above macro in some new class.
I guess i am missing some event handling.
Any pointers to proceed will be of great help.