[ERROR] There is no current GadgetList.

Just starting out? Need help? Post your questions and find answers here.
whizza
User
User
Posts: 46
Joined: Tue Nov 13, 2007 4:41 pm
Location: England

[ERROR] There is no current GadgetList.

Post by whizza »

Hi

I'm just looking for an explanation as to why '[ERROR] There is no current GadgetList' occurs when Help button is clicked prior to a number button being clicked.

Code: Select all


DTops=ExamineDesktops() 
Global DWx=DesktopWidth(0)/2 
Global DHy=DesktopHeight(0)/2 

If OpenWindow(0, 0, 0, DWx, DHy, "", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered) = 0
    MessageRequester("Error", "Can't open window", 0)
  End
EndIf  

Procedure ShowHelp()
  If OpenWindow(1, 0, 0, DWx, DHy, "Help", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered) = 0
    MessageRequester("Error", "Can't open help window", 0)
    End
  EndIf 
  
  EditorGadget(30, 10, 10, DWx-20, DHy-20, #PB_Editor_ReadOnly | #PB_Editor_WordWrap)
  AddGadgetItem(30, -1, "")
  AddGadgetItem(30, -1, "Help")
  AddGadgetItem(30, -1, "")
  
  Repeat
    Event = WaitWindowEvent()
    Select Event
          
      Case #PB_Event_CloseWindow
        CloseWindow(1)
        ProcedureReturn  
        
    EndSelect
  ForEver
EndProcedure


Procedure Startup()
  TextGadget(0, 10, 10, DWx-20, 60, "") 
  SetGadgetText(0, "Pick a number 1,2 or 3")
  
  ButtonGadget(1, 72, 80, 40, 40, "1")
  ButtonGadget(2, 114, 80, 40, 40, "2")
  ButtonGadget(3, 156, 80, 40, 40, "3")
  
  ButtonGadget(4, 10, 80, 60, 40, "Help")
  
  Repeat
    PickNumber = 0
    Event = WaitWindowEvent(1000)
    Select Event
      Case #PB_Event_CloseWindow
        End
      Case #PB_Event_Gadget
        PickNumber = EventGadget()
    EndSelect
    If PickNumber = 4
      ShowHelp()
      PickNumber = 0
    EndIf 
  Until PickNumber > 0     
  
  SetGadgetText(0, "Do you want gravy?")
  
; [ERROR] There is no current GadgetList. Occurs if Help clicked prior to a number.

  ButtonGadget(5, 10, 130, 60, 40, "Yes")
  ButtonGadget(6, 72, 130, 60, 40, "No")
  
  Repeat
    WantGravy = 0
    Event = WaitWindowEvent(1000)
    Select Event
      Case #PB_Event_CloseWindow
        End
      Case #PB_Event_Gadget
        WantGravy = EventGadget()
    EndSelect
  Until WantGravy > 0     
 
  SetGadgetText(0, "")
  
EndProcedure

Startup()

End

User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [ERROR] There is no current GadgetList.

Post by Mijikai »

Because u create a new gadget list with the new window.
-> UseGadgetList(WindowID)

Please use only one event loop for all windows!
whizza
User
User
Posts: 46
Joined: Tue Nov 13, 2007 4:41 pm
Location: England

Re: [ERROR] There is no current GadgetList.

Post by whizza »

So why does it work if coded as follows?

Code: Select all


DTops=ExamineDesktops() 
Global DWx=DesktopWidth(0)/2 
Global DHy=DesktopHeight(0)/2 

If OpenWindow(0, 0, 0, DWx, DHy, "", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered) = 0
    MessageRequester("Error", "Can't open window", 0)
  End
EndIf  

Procedure ShowHelp()
  If OpenWindow(1, 0, 0, DWx, DHy, "Help", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered) = 0
    MessageRequester("Error", "Can't open help window", 0)
    End
  EndIf 
  
  EditorGadget(30, 10, 10, DWx-20, DHy-20, #PB_Editor_ReadOnly | #PB_Editor_WordWrap)
  AddGadgetItem(30, -1, "")
  AddGadgetItem(30, -1, "Help")
  AddGadgetItem(30, -1, "")
  
  Repeat
    Event = WaitWindowEvent()
    Select Event
          
      Case #PB_Event_CloseWindow
        CloseWindow(1)
        ProcedureReturn  
        
    EndSelect
  ForEver
EndProcedure


Procedure Startup()
  TextGadget(0, 10, 10, DWx-20, 60, "") 
  SetGadgetText(0, "Pick a number 1,2 or 3")
  
  ButtonGadget(1, 72, 80, 40, 40, "1")
  ButtonGadget(2, 114, 80, 40, 40, "2")
  ButtonGadget(3, 156, 80, 40, 40, "3")
  ButtonGadget(4, 10, 80, 60, 40, "Help")

  ButtonGadget(5, 10, 130, 60, 40, "Yes")
  ButtonGadget(6, 72, 130, 60, 40, "No")
  HideGadget(5, 1)
  HideGadget(6, 1)

  Repeat
    PickNumber = 0
    Event = WaitWindowEvent(1000)
    Select Event
      Case #PB_Event_CloseWindow
        End
      Case #PB_Event_Gadget
        PickNumber = EventGadget()
    EndSelect
    If PickNumber = 4
      ShowHelp()
      PickNumber = 0
    EndIf 
  Until PickNumber > 0     
  
  SetGadgetText(0, "Do you want gravy?")

  HideGadget(5, 0)
  HideGadget(6, 0)

  Repeat
    WantGravy = 0
    Event = WaitWindowEvent(1000)
    Select Event
      Case #PB_Event_CloseWindow
        End
      Case #PB_Event_Gadget
        WantGravy = EventGadget()
    EndSelect
  Until WantGravy > 0     
 
  SetGadgetText(0, "")
  
EndProcedure

Startup()

End

User avatar
Kiffi
Addict
Addict
Posts: 1362
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: [ERROR] There is no current GadgetList.

Post by Kiffi »

whizza wrote:So why does it work if coded as follows?
Coincidence
Mijikai wrote:Please use only one event loop for all windows!
Hygge
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: [ERROR] There is no current GadgetList.

Post by Marc56us »

This is WaitWindowEvent() which should only be called once in a single loop. (look help WaitWindowEvent())

It is possible to make several loops, each containing a call to WaitWindowEvent() but it can become difficult to manage and especially it requires you to make a lot of code in several copies, like the code used to exit the program.

If an application is composed of several windows that some of them are supposed to do nothing when another one is active, then this allows to relieve the main program of the management of other events.

Thanks to PB for offering all these possibilities (which are often not found elsewhere)

So, in all other cases the right method is a single main loop to make sure you don't miss the other events.

And don't forget that you can also mix Event Loop and BindEvent

:wink:
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: [ERROR] There is no current GadgetList.

Post by TI-994A »

Technically, there's no strictly right or wrong way to do things; just tried and tested recommended ways.

Multiple event loops that don't process all messages might risk losing critical events. Timers, threads, and even menu and keyboard shortcuts will not be processed until their event loops resume, so it's always best to handle and process them all in one place.

Here's one approach to the example you'd posted:

Code: Select all

Enumeration
  #windowMain = 0
  #windowHelp
  
  #button1 = 0
  #button2
  #button3
  #buttonHelp
  #buttonYes
  #buttonNo
  #editorHelp
  #textStatus
  #listOrder
 
  #gravy = 0
  #fries
  #drink
  
  #show = 0
  #hide
EndEnumeration

DTops = ExamineDesktops()
Global DWx = DesktopWidth(0) / 2
Global DHy = DesktopHeight(0) / 2
Global wFlags = #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered

Procedure listContains(item.s)
  itemIndex = -1
  For i = 0 To CountGadgetItems(#listOrder) -1
    If GetGadgetItemText(#listOrder, i) = item
      itemIndex = i
      Break
    EndIf
  Next  
  ProcedureReturn itemIndex
EndProcedure

Procedure yesNo(state)   
  HideGadget(#buttonYes, state ! #True)
  HideGadget(#buttonNo, state ! #True)  
  If Not state
    SetGadgetText(#textStatus, "Pick a number 1, 2 or 3")   
  EndIf
EndProcedure

Procedure ShowHelp()
  If OpenWindow(#windowHelp, 0, 0, DWx, DHy, "Help", wFlags)    
    EditorGadget(#editorHelp, 10, 10, DWx-20, DHy-20, 
                 #PB_Editor_ReadOnly | #PB_Editor_WordWrap)
    AddGadgetItem(#editorHelp, -1, "")
    AddGadgetItem(#editorHelp, -1, "Help")
    AddGadgetItem(#editorHelp, -1, "")    
  Else 
    MessageRequester("Error", "Can't open help window")    
  EndIf
EndProcedure

Procedure Startup()
  If OpenWindow(#windowMain, 0, 0, DWx, DHy, "Main", wFlags)    
    TextGadget(#textStatus, 10, 10, 180, 50, "Pick a number 1, 2 or 3")    
    ListViewGadget(#listOrder, 210, 10, DWx - 220, DHy - 20) 
    ButtonGadget(#button1, 72, 80, 40, 40, "1")
    ButtonGadget(#button2, 114, 80, 40, 40, "2")
    ButtonGadget(#button3, 156, 80, 40, 40, "3")
    ButtonGadget(#buttonHelp, 10, 80, 60, 40, "Help")    
    ButtonGadget(#buttonYes, 10, 130, 60, 40, "Yes")
    ButtonGadget(#buttonNo, 72, 130, 60, 40, "No")
    yesNo(#False)
  Else
    MessageRequester("Error", "Can't open window")
  EndIf
EndProcedure

Startup()

Repeat
  Select WaitWindowEvent()
      
    Case #PB_Event_CloseWindow
      Select EventWindow()
          
        Case #windowMain
          appQuit = #True
          
        Case #windowHelp
          CloseWindow(#windowHelp)
          
      EndSelect
      
    Case #PB_Event_Gadget
      Select EventGadget()
          
        Case #button1
          yesNo(#True)
          question = #gravy
          SetGadgetText(#textStatus, "Do you want gravy?")
          
        Case #button2
          yesNo(#True)
          question = #fries
          SetGadgetText(#textStatus, "Do you want fries?")
          
        Case #button3
          yesNo(#True)
          question = #drink
          SetGadgetText(#textStatus, "Do you want a drink?")
          
        Case #buttonHelp
          ShowHelp()
          
        Case #buttonYes              
          yesNo(#False)
          
          Select question
              
            Case #gravy
              item$ = "add Gravy"
              
            Case #fries
              item$ = "add Fries"
              
            Case #drink
              item$ = "add Drink"
              
          EndSelect
          
          itemIndex = listContains(item$)
          If itemIndex < 0
            AddGadgetItem(#listOrder, -1, item$)              
          EndIf
                    
        Case #buttonNo
          yesNo(#False)
          
          Select question
              
            Case #gravy
              itemIndex = listContains("add Gravy")
              
            Case #fries
              itemIndex = listContains("add Fries")
              
            Case #drink
              itemIndex = listContains("add Drink")
              
          EndSelect
          
          If itemIndex >= 0
            RemoveGadgetItem(#listOrder, itemIndex)
          EndIf
          
      EndSelect         
      
  EndSelect
  
Until appQuit
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
whizza
User
User
Posts: 46
Joined: Tue Nov 13, 2007 4:41 pm
Location: England

Re: [ERROR] There is no current GadgetList.

Post by whizza »

Thanks everyone for the 'event loop' advice.

Thanks for the embellished example code TI-994A. Is there a reason you do not use 'UseGadgetList(WindowID)' as mentioned by Mijikai?
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: [ERROR] There is no current GadgetList.

Post by TI-994A »

whizza wrote:...Is there a reason you do not use 'UseGadgetList(WindowID)'...
The UseGadgetList() function is required only when creating new gadgets for a window after other windows have been created.

Code: Select all

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered

; opening a window starts a new gadget list automatically
OpenWindow(1, 0, 0, 300, 200, "Window 1", wFlags)

; all gadgets created hereafter belongs to Window 1
TextGadget(0, 10, 10, 280, 40, "A label for Window 1")
StringGadget(1, 10, 60, 280, 40, "A text box for Window 1")

; again, opening a window starts a new gadget list automatically
OpenWindow(2, 0, 0, 300, 200, "Window 2", wFlags)

; all gadgets created hereafter belongs to Window 2
TextGadget(2, 10, 10, 280, 40, "A label for Window 2")
StringGadget(3, 10, 60, 280, 40, "A text box for Window 2")

; to create more gadgets for Window 1, call UseGadgetList()
UseGadgetList(WindowID(1))

; all gadgets created hereafter belongs to Window 1
ButtonGadget(4, 10, 140, 280, 50, "A button for Window 1")

; to create more gadgets for Window 2, call UseGadgetList()
UseGadgetList(WindowID(2))

; all gadgets created hereafter belongs to Window 2
ButtonGadget(5, 10, 140, 280, 50, "A button for Window 2")

; for clarity, move windows next to each other instead of overlapping
ResizeWindow(1, WindowX(1) - 200, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeWindow(2, WindowX(2) + 200, #PB_Ignore, #PB_Ignore, #PB_Ignore)

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
BlindMan
User
User
Posts: 32
Joined: Thu Aug 30, 2018 11:34 am

Re: [ERROR] There is no current GadgetList.

Post by BlindMan »

TI-994A wrote:The UseGadgetList() function is required only when creating new gadgets for a window after other windows have been created.

Thanks for clarification TI-994A.


And if not using UseGadgetList() the number used to identify new gadgets created in secondary windows must be greater than the highest number used when creating gadgets in the primary window? IE. Primary window has gadgets 0 to 30 defined before opening secondary window. New gadgets created in secondary window must have id number greater than 30.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: [ERROR] There is no current GadgetList.

Post by TI-994A »

BlindMan wrote:...Primary window has gadgets 0 to 30 defined before opening secondary window. New gadgets created in secondary window must have id number greater than 30.
Not really. Gadget numbers can be assigned arbitrarily across different windows without any particular sequence. The only rule to follow is not to overwrite any gadget by re-using the same gadget number.

Here, the gadget numbers are not assigned sequentially, and are not grouped in any cluster between the two windows:

Code: Select all

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered

; opening a window starts a new gadget list automatically
OpenWindow(1, 0, 0, 300, 200, "Window 1", wFlags)

; all gadgets created hereafter belongs to Window 1
TextGadget(9, 10, 10, 280, 40, "A label for Window 1")
StringGadget(3, 10, 60, 280, 40, "A text box for Window 1")

; again, opening a window starts a new gadget list automatically
OpenWindow(2, 0, 0, 300, 200, "Window 2", wFlags)

; all gadgets created hereafter belongs to Window 2
TextGadget(0, 10, 10, 280, 40, "A label for Window 2")
StringGadget(5, 10, 60, 280, 40, "A text box for Window 2")

; to create more gadgets for Window 1, call UseGadgetList()
UseGadgetList(WindowID(1))

; all gadgets created hereafter belongs to Window 1
ButtonGadget(1, 10, 140, 280, 50, "A button for Window 1")

; to create more gadgets for Window 2, call UseGadgetList()
UseGadgetList(WindowID(2))

; all gadgets created hereafter belongs to Window 2
ButtonGadget(11, 10, 140, 280, 50, "A button for Window 2")

; for clarity, move windows next to each other instead of overlapping
ResizeWindow(1, WindowX(1) - 200, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeWindow(2, WindowX(2) + 200, #PB_Ignore, #PB_Ignore, #PB_Ignore)

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply