Forum > Cocoa

[Solved] Unfocussed application form does not close on closing application

(1/3) > >>

Hansaplast:

This has been around for quite a while already and I started to wonder if this is just me or a bug.


When an application is open, and its form is visible and focussed (!), right clicking the icon in the dock and selecting "Quit" closes the application and the form as expected.
However, when the application does not have focus, right clicking the icon in the dock and selecting "Quit" will do nothing. The application remains open, the form remains visible ... until you give the application form focus again.


Is this expected behavior? Am I missing something here? Or is this a bug?


Steps to reproduce:


* Create a new blank application in Lazarus.
* Run it (I ran it without debugger).
* Now bring another application to the front (focus).
* In the dock, right click the newly created Lazarus application icon and select "Quit".
* Nothing happens.
* Move the mouse over the form, nothing happens.
* Click the form: the form and application now terminate. Tested with macOS Monterey, Lazarus 2.3.0 (rev main-2_3-2069-g4aa7b5b350) FPC 3.2.2, tested on Intel and AARCH64.
This is not a new phenomena, I've seen it with several other macOS and Lazarus versions as well.
It does however seem Cocoa specific (cannot test Carbon anymore, and I do recall seeing this to happen under Windows or Linux).

KodeZwerg:
On Windows I do not know such matters.
On Windows I would try investigate with its Messages (WM_CLOSE for example) to see if application receive it.
I am sorry that I can not tell how to do on non-Windows, maybe try with a memo as log, within "OnClose" event log it to memo to see that application tries to.
(if you can log but app not close, maybe try "Application.Restore" in "OnClose"-Event ?)
Maybe this has to do with memory garbage collection and auto clean... ?

Hansaplast:
Thanks for chiming in KodeZwerg!


The OnClose event does actually get fired (tested based on your suggestion).
When I change the form caption in the OnClose caption, it actually does change the form caption as expected - yet the form doesn't close.


Some random things I tried in the OnClose event, and none of them do anything until the form receives focus again:

* Application.Terminate doesn't do anything,
* set "CloseAction" to "caFree" doesn't seem to so anything either,
* self.SetFocus doesn't do anything,
* self.SetFocusedControl(self) same resultNote:
With each of these tests, having self.caption:='123'; in the OnClose event worked, and the caption would actually change. The listed tests were done individually with changing the caption before and after the listed things.


Other observations:
- The icon remains visible in the Dock until the form closes.
- Right clicking the icon in the dock, allows me to select Quit, over and over again, until the form is closed.
- Left clicking the icon in the dock, after having done a "Quit", actually does close the form and application.
- Multiple calls changing the caption works,
- Calling "ShowMessage('123')" works, but the dialog remains behind the other active application.

KodeZwerg:
Give this a try:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);begin  Application.Restore;  if (not Self.Visible) then    Self.Show;  Self.BringToFront;  Action := caFree;end;

Hansaplast:


Oh wow ... that worked!  8)
By process of elimination, self.show seemed to do the trick.


Now, since Windows (for example) doesn't need this; should this be considered a bug or not?
Also: is setting the CloseAction needed or just good practice? (just asking since I never really use it)



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin  // Application.Restore;  // if (not Self.Visible) then    Self.Show;  // Self.BringToFront;  // CloseAction := caFree;end;          

Navigation

[0] Message Index

[#] Next page

Go to full version