
| Subject: | Closing a form and a thread |
| Posted by: | Roy Lambert (roy.lambe…@skynet.co.uk) |
| Date: | Fri, 30 Apr 2010 |
I have a message handler
procedure TMainForm.MainHWNDHandler(var msg: TMessage);
begin
case msg.Msg of
 ProgressReport: TellEMSearchStatus(msg);
 jmpRequired: ProcessJumpInstruction(msg);
 StatusMessage: ChangeStatusMessage(msg);
 PinToJump: AddToJumpButton(msg);
 OpenViewHistory: OpenViewHistoryForm(msg);
 SubsidForm: MakeSubsidiaryForm(msg);
 OpenMainForm: RemoteOpenMainForm(msg);
 InitialLogon: DoInitialLogon(msg);
 CloseSubsidTab: CloseNonMainTab(msg);
 StartPhoneTimer: DialedStartStopwatch(msg);
 StopPhoneTimer: DialedStopStopwatch(msg);
 AlarmsRunning: SetAlarmRunningStatus(msg);
 AlarmThreadCrash: AlarmsNotWorking(msg);
 CurrentAlarmCheck: FlipAniStatus(msg);
 PageSwap: GotoLastPage(msg);
 AskForJmpVars: DoAskForJmpVars(msg);
else DefWindowProc(Self.Handle, msg.Msg, msg.wParam, msg.lParam);
end;
end;
and in the OnClose (I've also tried OnCloseQuery) I politely ask the thread to die. It does so, and as part of its demise it posts a message back to the main form to let it know its gone. Unfortunately the main form doesn't seem to be getting the message. I have a sleep loop
 while LTCAlarmCheck.Active or NewEMailCheck.Active or ProjectAlarmCheck.Active do Sleep(10);
to prevent me closing the form before the thread has gone (it needs to close and release a number of database links) but I just sleep forever.
Does message handling die when closing the form?
Roy Lambert