ModalForm don't close once openeed lazarus / 31-LCL ---------------------------------------------------------------------- magnomp · 2016-07-11 21:01 I cant close any form once showed them If I click the X button, nothing. If I set ModalResult to anything, nothing. I got no exception (I log via TApplicationProperties.OnException). The forms are not autocreate, I create them before showing. The OnClose is just: procedure TFrmBase.FormClose(Sender: TObject; var CloseAction: TCloseAction); begin   if FreeOnClose then     CloseAction := caFree   else     CloseAction := caHide; end; Don't have OnCloseQuery I can't fill a sample cause it doesn't even happen on my machine, but on a customers. My machine is Windows 10, Lazarus 1.6 x86 The customer is a Windows 7 x64 ---------------------------------------------------------------------- RAW · 2016-07-11 22:32 I bet this will do...  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure TFrmBase.SaveQuit; Begin  // Save first :-)  Application.Terminate; End;   EDIT: Then you can use CanClose:= False (OnCloseQuery)... if you want... ---------------------------------------------------------------------- RAW · 2016-07-12 00:00 OK, I overlooked "MODAL" Form, but what you described is working very fine for me: When I start this and press Button2 (FreeOnClose:= True) and then press Button1 to show the ModalForm, then I can close the ModalForm as expected and when I close the Program then I can see there is nothing left in RAM. And when I press Button3 (FreeOnClose:= False) and close the ModalForm and the MainForm then the ModalForm stays in RAM. So it's working very fine.... what's the problem??? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Unit uAppTerminate; {$mode objfpc}{$H+}Interface USES  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;  TYPE  TFrmBase = Class(TForm)      Button1: TButton;   Button2: TButton;   Button3: TButton;           Procedure Button1Click (Sender: TObject);    Procedure Button2Click (Sender: TObject);    Procedure Button3Click (Sender: TObject);            Procedure MyClose      (Sender: TObject;  Var CloseAction: TCloseAction);       PRIVATE     ModalForm  : TForm;       FreeOnClose: Boolean;   End;  VAR  FrmBase: TFrmBase; Implementation {$R *.lfm}  // Standard WayProcedure ShowAForm;  Var   Form: TForm; Begin  Form:= TForm.Create(Nil);   Try    Form.Position:= poScreenCenter;    Form.Height  := 500;    Form.Width   := 500;        Form.ShowModal;   Finally    Form.Release;    Form:= Nil;   End;   End;  Procedure TFrmBase.Button1Click(Sender: TObject); Begin  ModalForm         := TForm.Create(Nil);  ModalForm.Position:= poScreenCenter;  ModalForm.Height  := 500;  ModalForm.Width   := 500;  ModalForm.OnClose := @MyClose;          ModalForm.ShowModal; End;  Procedure TFrmBase.MyClose(Sender: TObject; Var CloseAction: TCloseAction); Begin  If FreeOnClose  Then CloseAction:= caFree  Else CloseAction:= caHide; End;    Procedure TFrmBase.Button2Click(Sender: TObject); Begin  FreeOnClose:= True; End;  Procedure TFrmBase.Button3Click(Sender: TObject); Begin  FreeOnClose:= False; End;  End. ---------------------------------------------------------------------- magnomp · 2016-07-13 13:39 I can't reproduce it either, I only see this behaviour on a single customer machine Also it's worth to mention that I put a timer that logs periodically ModalResult and can confirm that it IS set to mrOk while the form remains active and responsive