Error creating gadget

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Error creating gadget

Post by AZJIO »

1. Click the "Add" button, a new button will appear.
2. Start again and first click the “Properties” button, then “Add”. We get the error "There is no current GadgetList."

Code: Select all

; 1. Click the "Add" button, a new button will appear.
; 2. Start again and first click the “Properties” button, then “Add”. We get the error "There is no current GadgetList."

#Window = 0
#Win1 = 1
Procedure Properties()

	DisableWindow(#Window, 1)
	
	OpenWindow(#Win1, 0, 0, 200, 133, "Properties", #PB_Window_SystemMenu | #PB_Window_ScreenCentered, hGUI)
	CheckBoxGadget(3, 10, 10, 180, 20, "CheckBox")
	ButtonGadget(4, (200 - 70) / 2, 133 - 40, 70, 28, "OK")

	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 4
						Break
				EndSelect
			Case #PB_Event_CloseWindow
				Break
		EndSelect
	ForEver
	
	FreeGadget(3)
	FreeGadget(4)

	DisableWindow(#Window, 0)
	CloseWindow(#Win1)
EndProcedure


hGUI = OpenWindow(#Window, 0, 0, 220, 300, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If hGUI
	ButtonGadget(1, 10, 10, 99, 30, "Properties")
	ButtonGadget(2, 120, 10, 69, 30, "Add")
	
	ButtonGadget(5, 10, 50, 26, 30, "11")
	ButtonGadget(6, 50, 50, 26, 30, "22")

;- Loop
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 1
						Properties()
					Case 2
						ButtonGadget(7, 166, 50, 30, 30, "33")
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(#Window)
				End
		EndSelect
	ForEver
EndIf
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: Error creating gadget

Post by captain_skank »

Hi,

You can use :

UseGadgetList(WindowID(GetActiveWindow()))

in your event loop to fix it.

not sure if that helps explain it though

Cheers
Mesa
Enthusiast
Enthusiast
Posts: 433
Joined: Fri Feb 24, 2012 10:19 am

Re: Error creating gadget

Post by Mesa »

Code: Select all

; 1. Click the "Add" button, a new button will appear.
; 2. Start again and first click the “Properties” button, then “Add”. We get the error "There is no current GadgetList."

#Window = 0
#Win1   = 1
Procedure Properties()
  
  DisableWindow(#Window, 1)
  
  OpenWindow(#Win1, 0, 0, 200, 133, "Properties", #PB_Window_SystemMenu | #PB_Window_ScreenCentered, hGUI)
  CheckBoxGadget(3, 10, 10, 180, 20, "CheckBox")
  ButtonGadget(4, (200 - 70) / 2, 133 - 40, 70, 28, "OK")
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 4
            Break
        EndSelect
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
  
  FreeGadget(3)
  FreeGadget(4)
  
  DisableWindow(#Window, 0)
  CloseWindow(#Win1)
  
  
EndProcedure


hGUI = OpenWindow(#Window, 0, 0, 220, 300, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If hGUI
  ButtonGadget(1, 10, 10, 99, 30, "Properties")
  ButtonGadget(2, 120, 10, 69, 30, "Add")
  
  ButtonGadget(5, 10, 50, 26, 30, "11")
  ButtonGadget(6, 50, 50, 26, 30, "22")
  
  ;- Loop
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            Properties()
          Case 2
            SetActiveWindow(#Window)
            UseGadgetList(WindowID(#Window))
            ButtonGadget(7, 166, 50, 30, 30, "33")
        EndSelect
      Case #PB_Event_CloseWindow
        CloseWindow(#Window)
        End
    EndSelect
  ForEver
EndIf
Post Reply