Returning True in Window.CancelClose not working

Normally returning true in Window.CancelClose should stop the window from closing, and also stop the App from quitting.

I have a project here in which I’m returning True in this event, and it’s not stopping anything. The app just quits every time, no matter what I return here.

Under what circumstance would this happen? I’ve looked around for other calls to close or quit, and can’t find any. What’s going on?


My guess is it’s not really returning True where you think it is. Did you try setting a breakpoint to make sure?

Yes, I set a breakpoint, and it was returning True where it should, at the end of that event.

I didn’t trust that and just commented it all out and wrote RETURN TRUE at the top of the event. Same result.

Hmmm… Did you trace past that to make sure some super class isn’t overriding the result?

I did, and didn’t see anything suspect. The Window IS indeed one of my own classes. Implicit Instance is OFF.

Could it be a silent crash ?

Is a silent crash traceable somehow?

My Window class does have code in its CancelClose event, which calls a shadowed CancelClose event as follows:

me.IsClosing = not RaiseEvent CancelClose( appQuitting )

I set this flag IsClosing in order to suppress the Activate event from firing during close (the event fires on Mac during the close sequence when the user closes a modal dialog in the window)

Is it illegal to shadow the CancelClose event? (I hope what I’m asking is clear?)

OH, DUH!!! Gosh, how embarrassing.

I forgot to return a value in the class’s CancelClose event!

return not  me.IsClosing

So in my class I need

  me.IsClosing = not RaiseEvent CancelClose( appQuitting )
  return not me.IsClosing

This is one of those times I wish the IDE would tell me when I haven’t returned a value.

Thank you Kem for the winning clue. It was staring me in the face and I just didn’t see it.

We’ve all been there.