Can't Display Window Based on Array of Window Names

I’m attempting to track open windows so that, when users press the BACK button on any window, the current window will close and the previously open window will open again. I have two methods, ScreenAdvance and ScreenBack, stored in a public module and called by prefixing the module name to the Method (e.g., ModuleName.ScreenAdvance(parm1 as window, parm2 as string)).

I have an array in the APP object of type WINDOW called winScrnHistory()
I also have a parallel array in the APP object of type STRING called strScrnHistory()

As I open a new window, the window name is added to the winScrnHistory() array and it’s added as a string to the strScrnHistory() array. As the user closes a window, I remove the UBound element from both arrays.

When the user navigates to a new window, I close the window in the UBound array element:
App.winScrnHistory(UBound(App.winScrnHistory)).Close //close ubound window

I then append the requested window as WINDOW and string to the two arrays and .Show the window as follows:
winNextScr.Show //open new window

All works fine so far.

When the user clicks the BACK button, I call ModuleName.ScreenBack. This Method first closes the currently opened screen with the following:
App.winScrnHistory(UBound(App.winScrnHistory)).Close //close ubound window

That works fine. Then I remove the UBound element from both arrays, which results in a UBound value 1 less than before. I then attempt to open the new UBound window with the following:


This statement, however is ignored by Xojo. No exception is raised.

When I change the statement to have a specific index such as:

… and that works fine. But, of course, I want to dynamically look at the UBound element of the array and open it, so I can’t hard code the index #.

So I then tried to execute the .Show right after the .Close statement, before removing elements from the array, using this statement:
App.winScrnHistory(UBound(App.winScrnHistory)).Show //REOPEN just-closed ubound window

And that statement was ignored by Xojo also.

Should this not work, or am I using unsupported syntax? Is there a better way to do this?

Thanks for any insight!

Have you checked in the debugger that you get the correct window? No code statements are ignored by Xojo. Check in the debugger what happens. If you still can’t figure it out then make a code example and post it here.

It seems you are using a metaphor not unlike an Internet browser.

It would probably be cleaner and more user friendly to have one window that does not move, and switch Container Controls inside.

Note that the work you have done so far would not be wasted : you can turn any window into a Container Control by changing its Super to “ContainerControl”. It then becomes an embedded window.

It will also be much simpler, as Container Controls do not show up like windows with implicit instantiation, so you can store all of them in the array where they will keep their index, and will not need cumbersome management.

Thanks very much for the input. I’ve done some more exploring, and this is what I’ve found so far. I will move to the Containercontrol suggestion (thank you, Michel), because that seems to be the more appropriate way to accomplish what I’m doing in the Xojo object-oriented environment. However, I’m still very curious as to why my syntax seems be skipped over with no error, and after the ScreenBack function is completed, the program simply stops – presumably because the new window has not been displayed, as requested.

The Debugger is showing that it’s on the right window. However, the window variable name is WindowVariable.WindowVariable . I’m not sure I understand the syntax as reported by the Debugger. When I open a window in my ScreenAdvance function, the same type of Window Name is reported, and it works fine. This is the Method that advances the screen to the one as indicated by the user’s button press:

If UBound(App.winScrnHistory) > 0 Then MsgBox "Closing UBound Window: " + App.strScrnHistory(UBound(App.winScrnHistory)) App.winScrnHistory(UBound(App.winScrnHistory)).Close //close ubound window End If App.winScrnHistory.Append(winNextScr) //add new window to array App.strScrnHistory.Append(strNextScr) //add new window name to parallel array MsgBox "DEV NOTE ScreenAdvance: About to show next window: " + strNextScr winNextScr.Show //open new window

This is the code that goes back a screen. I’ve changed the code around to display the next window using identical syntax to the above function.

[code]Dim intScreenUB as Integer
Dim winScreenUB as Window

If UBound(App.winScrnHistory)>=0 then
App.winScrnHistory(UBound(App.winScrnHistory)).Close //close ubound window

intScreenUB = UBound(App.winScrnHistory)
App.winScrnHistory.Remove(intScreenUB) //this decreases ubound value by one
App.strScrnHistory.Remove(intScreenUB) //remove ubound window name in parallel string array

intScreenUB = UBound(App.winScrnHistory)

winScreenUB = App.winScrnHistory(intScreenUB)

End If

When the next window to display is frmSettings, the debugger shows: frmSettings.frmSettings. It shows the correct intScreenUB value, which is the UBound value of the arrays holding names of open windows (parallel arrays: 1 String type, 1 Window type).

Thank you again for any help.