Activate event + Windows + close

We have noticed several times, especially on MSWindows that the “Activated” event of a window fires when the window is about to be closed.
The problem is that this event can use controls… which are gone…
Naturally, we are unable to reproduce this issue, but it happens many times at our clients…
Is it a Xojo Bug ?
For me, when a window is going to be closed (after the CancelClosing event) : no interest to call the Activated event.
I am tired of putting “try…end try” to fix this issue…

You could set a flag (e.g., quitting as Boolean) in the CancelClosing event, and then check for that being True in Activated, just return if so.

I would think that one shouldn’t have to. Personally I have never seen this behavior, so I would recommend OP perform a thorough code review of the code in their CancelClose and Close events.

There are several things a developer can do in those events that would inadvertently bring the window to the front which could raise Activated.

My first step would be to check and turn off ImplicitInstance.

1 Like

Thanks but ImplicitInstance is deprecated and not used in API 2.
Anyway, when you return false from CancelClosing, you say “Hey close this window” and no need to call other events (except the Closing event).

As Tim says.
if the window is activated after to return FALSE in Cancel close, what happens in the Close event?
Does it setfocus to something, or affect controls in any way?

That is not correct. DesktopWindow.ImplicitInstance

Vincent means that on new Xojo projects Implicit Instance is Off by default:

Edit: I have an option in Override file to make it Off by default.

Are you sure you don’t have a custom DesktopWindow template? I just launched 2024r1.1 to verify that this very long discussion about changing the behavior actually went the direction we wanted, but found Implicit Instance on by default for a brand new DesktopWindow.

1 Like

I’m sorry, I just remember that we talked about this before and I tested if possible to make that as default.

You are right, I added ImplicitInstance=False to DesktopWindow.defaults override file.
Sorry for the noise.
Getting (very) old, memory is not the same.

Edit: for those who don’t know, you can create a file called DesktopWindow.defaults in
Documents/Xojo/Overrides/DesktopWindow.defaults
with text like this:

Width=1000
Height=600
MinimumWidth=800
MinimumHeight=600
ImplicitInstance=False

that will create your new DesktopWindows with a different default size, minimum size and Implicit Instance.

1 Like

Your input is never noise! :heart:

1 Like

Right :slight_smile: