I'm testing a multi-GUI program. In this example you will see a problem when opening "gui1", closing it, then opening "gui2"...
I need advice to handle this correctly. Should I reset gadget's variables to 0 when I close the "child" gui ?
Code: Select all
Global main_gui
Global button1, button2
Global gui1, gui2
Global buttonA, buttonB
Global buttonC, buttonD
Procedure open_gui1()
gui1 = OpenWindow(#PB_Any, 100, 200, 195, 260, "Gui1 Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
buttonA = ButtonGadget(#PB_Any, 5, 5, 70, 22, "buttonA")
buttonB = ButtonGadget(#PB_Any, 5, 35, 70, 22, "buttonB")
EndProcedure
Procedure open_gui2()
gui2 = OpenWindow(#PB_Any, 100, 200, 195, 260, "Gui2 Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
buttonC = ButtonGadget(#PB_Any, 5, 5, 70, 22, "buttonC")
buttonD = ButtonGadget(#PB_Any, 5, 35, 70, 22, "buttonD")
EndProcedure
main_gui = OpenWindow(#PB_Any, 100, 200, 195, 260, "Main Window", #PB_Window_SystemMenu)
If main_gui
button1 = ButtonGadget(#PB_Any, 5, 5, 50, 22, "button1")
button2 = ButtonGadget(#PB_Any, 5, 35, 50, 22, "button2")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Select EventWindow()
Case main_gui
Quit = 1
Case gui1
Debug "close gui1"
CloseWindow(gui1)
Case gui2
Debug "close gui2"
CloseWindow(gui2)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case button1
open_gui1()
Case button2
open_gui2()
Case buttonA
Debug "buttonA"
Case buttonB
Debug "buttonB"
Case buttonC
Debug "buttonC"
Case buttonD
Debug "buttonD"
EndSelect
EndSelect
Until Quit = 1
EndIf

