Si può avere il MainForm assegnare un gestore di eventi OnClose
o OnDestroy
ad ogni figlio MDI che crea. Ogni volta che un client MDI viene chiuso/distrutto, il gestore può controllare se altri moduli figlio MDI sono ancora aperti e, in caso contrario, fare ciò che è necessario fare.
procedure TMainForm.ChildClosed(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
// the child being closed is still in the MDIChild list as it has not been freed yet...
if MDIChildCount = 1 then
begin
// do work
end;
end;
Oppure:
const
APPWM_CHECK_MDI_CHILDREN = WM_APP + 1;
procedure TMainForm.ChildDestroyed(Sender: TObject);
begin
PostMessage(Handle, APPWM_CHECK_MDI_CHILDREN, 0, 0);
end;
procedure TMainForm.WndProc(var Message: TMessage);
begin
if Message.Msg = APPWM_CHECK_MDI_CHILDREN then
begin
if MDIChildCount = 0 then
begin
// do work
end;
Exit;
end;
inherited;
end;
fonte
2013-09-04 00:14:35
+1 Nizza! Meglio del mio. ;-) – NGLN
@NGLN - Grazie! La tua è più potente, nel caso in cui tu abbia bisogno di sapere quando un bambino fa questo e quello ... :) –
NGLN, Sertac Akyus e Remy Lebeau. Grazie per le tue risposte, tutte eccellenti. Sei molto bravo. Per questa mia situazione, il codice migliore era Sertac Akyuz. È più semplice e risolto il mio problema. NGLN e Remy, ho salvato il tuo codice per le situazioni future. Grazie. – Delphiman