CloseButton, single window <>>> appQuitting

I recently started using the CloseButton to quit the App.
It doesn’t work. Quit works if I use the menuItem.

I had to check it, but appQuitting in that window is not set to True.
I also verified this window is the sole window.

Is this normal now?

You are posting in “General”. In the macOS Forum, i’d answered “yes” and you can change this with App.AutoClose = True in the App.Open Event. :wink:

I posted in General because appQuitting wasn’t set in CancelClose on PC and Mac.

For some reason, I had taken the line out. It goes back in.

Also the analyzer didn’t like it on the first try. Weird.

Sorry, my fault:

App.AutoQuit = True

Thank you very much.
It’s not mentioned in the LR under [quote]Window.CancelClose[/quote]
It isn’t easy to find even with the misspelling.

You can find more information at:

And because:

your App may not quit after you have closed the last open Window.

Kind regards, Schneppi :slight_smile:

Actually that isn’t the answer. I already had AutoQuit in there.

[quote=397931:@Arthur Gabhart]Actually that isn’t the answer. I already had AutoQuit in there.

As a workaround, try to call “Quit” in the Close event of the Window?

But better set a Break in the Close Event and investigate in the Debugger what exactly happens once you Clicked the Close Button.

I addedIf WindowCount = 1 Then appQuitting = True End If
and its works. Sigh for defensive coding

It sounds like you’ve got some funky code in your window’s cancelClose event. Setting appQuitting to True normally wouldn’t have any effect. So something else is going on.

Take a step back and create a fresh, empty project. In app.Open put

app.AutoQuit = True

Run the app and close the window. The app will quit and close the Run tab in the IDE.
Change that to

app.AutoQuit = False

Run the app and close the window. The app will remain running in the background and the Run tab will remain open.

Now go back to your project and look for why it doesn’t work that way for you.

Under normal circumstances I would agree.
I debug this by putting a stop at the very beginning of CancelClose.
At this very point, with one window open, it has appQuitting = false.

Ah. Now I get it. Yes, that is correct, regardless of app.AutoQuit. At that point, the app has not chosen to quit yet. And in fact, you can prevent the app from quitting by returning True from the CancelClose (which also keeps the window from closing).

The difference between closing the window via the X button and closing it via File -> Exit is

When you close the window via the X button

  1. Window.CancelClose is called (appQuiting = False)
  2. If it returns False, then Window.Close is called
  3. If that was the last window open, then the app decides to close
  4. app.CancelClose is called
  5. If that returns False, then app.Close is called.

If you use the File->Exit menu item

  1. app.CancelClose is called
  2. If that returns False, then the app attempts to close all windows
  3. Window.CancelClose is called (appQuitting = True)
  4. if that returns False, then Window.Close is called
  5. If all windows return False from CancelClose, then app.Close is called

appQuiting will only ever be True if you use the menu. It is there so the window can differentiate between the window being closed by the user directly, or if the window is being closed because the user is quitting the app. Eg., you may have code in Window.CancelClose that prevents the window from closing under some condition, but you’ll want to skip that code if the user is closing the app so you don’t prevent it from quitting.

Okay. If I close, with only one window, and with the button, AppQuitting = false.
How do I tell the stuff in CancelClose to believe it is quitting, or as in my program: App.QTing = True
If App.QTing = True then the stuff is ignored.

Also to clarify:
AppQuitting = True if from a menubutton
AppQuitting = false if from the close button and it is actually quitting
AppQuitting = false if from the close button and it is NOT actually quitting.

You might consider refactoring the code. You may have stuff in the window that should really be application-wide. Otherwise, your test for WindowCount = 1 will work.