Tom F 85 Posted January 15, 2021 I create a non-modal form like this: procedure TForm1.Button1Click(Sender: TObject); begin FNonModalForm := TForm2.Create(Self); FNonModalForm.Show; end; What's a good way to have a non-modal Form2 signal its owner Form1 that the non-modal form has been closed by the user so the owner can free Form2? AFAIK, it can't be done in a callback from Form2.FormClose because that's too early for the owner Form1 to free Form2. Send a Windows message to the owner form? Share this post Link to post
Attila Kovacs 631 Posted January 15, 2021 in OnClose Action := caFree; 1 Share this post Link to post
Tom F 85 Posted January 15, 2021 Is Assigned(FNonModalForm) false after that statement? Share this post Link to post
Attila Kovacs 631 Posted January 15, 2021 A TForm or descendant has an event OnClose. Quote procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction); begin Action := caFree; end; Thats it. No further interaction needed. Share this post Link to post
Remy Lebeau 1436 Posted January 15, 2021 (edited) 2 hours ago, Tom F said: Is Assigned(FNonModalForm) false after that statement? No. You have to reset it manually. 1 hour ago, Attila Kovacs said: A TForm or descendant has an event OnClose. Thats it. No further interaction needed. Unless the parent form needs to reset its FNonModalForm variable, in which case you would need to move the OnClose handler to the parent form instead, eg: procedure TForm1.Button1Click(Sender: TObject); begin if FNonModalForm = nil then begin FNonModalForm := TForm2.Create(Self); FNonModalForm.OnClose := NonModalFormClosed; end; FNonModalForm.Show; end; procedure TForm1.NonModalFormClosed(Sender: TObject; var Action; TCloseAction); begin FNonModalForm := nil; Action := caFree; end; Edited January 15, 2021 by Remy Lebeau 4 Share this post Link to post
Attila Kovacs 631 Posted January 15, 2021 @Remy Lebeau ah, right, I missed that part, I just read the title. Share this post Link to post
Tom F 85 Posted January 16, 2021 Thanks, Remy! That's what I needed. It never occurred to me to hook the OnClose event itself! Share this post Link to post