dismissing dialog using ShowModalWithin does not return to code execution

I guess the dialog has a document frame when using ShowModal and a Sheet frame when using ShowModalWithin, so since the bug occurs with ShowModalWithin, then to answer your question, the dialog is being set as a Sheet Window.

What frame type does the window you’re showing using ShowModal / ShowModalWithin have at design time ?
Thats relevant

The parent window is a frame type Document.

What type is d in this code you posted ?

b = d.ShowModalWithin(w)

What frame type doe that window have ?
THAT is relevant

The dialog is cast as MessageDialog and shown with ShowModalWithin. The complete code is above. Is there some other way to set the frame type of the dialog? I don’t see anything about this in the LR. Sorry, but it seems like I’ve given all this information, and I don’t understand your question.

I’d missed that you’d posted the code

opened 2015r2.4

lifted your code
stuck it in the action event of a button
made my app.open event opened several copies of the window
pressing the button I get the dialog & it always returns to the code right after dismissing the dialog

so I’m stumped

Don’t put the code in the action event. Put it in the CancelClose event of the window and close each window.

Still no issue here regardless of whether I close them manually by clicking the close button or quitting the app

or if I have an additional window that closes all the others before closing itself

showmodal & showmodalwithin both behave as expected

Okay. Thanks for trying.

I get the bug as I described every time. Any idea what could cause it?

Seems like since this was in fact previously filed as a bug through feedback, and verified as a bug in a previous version, that there should be some clue that could be shared about this.

Can you post the project or a smaller version of the project that demonstrates the bug?

I found a big clue:

When the dialog is shown as ShowModalWithin( parentWindow ) , when the user dismisses it, the Activate event of the parent window is fired. Activate is not fired if the dialog uses ShowModal instead of ShowModalWithin.

Having code in the parent window’s Activate event which tries to assign that window’s reference to something else is what causes the bug.

!!! If there is code in the parent window’s Activate event which tries to assign that window’s reference to something else, that is what causes the bug !!!

Here’s how I get around the problem:

  1. make a subclass of the Window class (my parent windows were already subclasses)
  2. add a property to the subclass called me.IsClosing
  3. add an event handler for CancelClose with the following code

me.IsClosing = true me.IsClosing = RaiseEvent CancelClose( appQuitting )
4. define a new event CancelClose to shadow the existing CancelClose event (this is what will be raised in the code in 3.)
5. add an event handler for Activate with the following code

  if not IsClosing then RaiseEvent Activate
  1. define a new event Activate to shadow the existing Activate event (this is what will be raised in the code in 5.)

This ensures that the Activate event will not be called when the modal dialog sheet window closes within the parent, when that code is called from the CancelClose event, and that solves the problem.

Should this still be called a bug in Xojo that needs to be fixed? I’m not sure. I added this text to <https://xojo.com/issue/20701> although after pasting the numbers did not show up :confused: