Hi all
Am starting to lose hair over this one... so hopefully someone can help me...
I have a structure to store some names I take from a database, and two gadgets - one for the button and one for the associated label:
Code:
Structure ListOfNamesStructure
FirstName.s
LastName.s
NameGadgetNumber.i
ButtonGadgetNumber.i
EndStructure
Global Dim ListOfNamesArray.ListOfNamesStructure(0)
Then, I create the gadgets associated with this dynamically into a scroll area, and pop the gadget numbers into the structure:
Code:
OpenGadgetList(#ScrollArea_ChooseNameFromList)
For n = 0 To ArraySize(ListOfNamesArray())
ListOfNamesArray(n)\ButtonGadgetNumber = ButtonGadget(#PB_Any,0,(n*40)+10,50,20,ActionSelected)
ListOfNamesArray(n)\NameGadgetNumber = TextGadget(#PB_Any,60,n*40,GadgetWidth(#ScrollArea_ChooseNameFromList)-100,40,ListOfNamesArray(n)\LastName + ", " + ListOfNamesArray(n)\FirstName)
Next
CloseGadgetList()
So far, so good. The structure contains all the gadgets, so I can free them when needed. Now all I need to do is make things happen when I click the relevant button (e.g. pass the relevant location through to a procedure to make things happen)... however:
Code:
Repeat
Event = WaitWindowEvent(100)
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case ListOfNamesArray(0)\ButtonGadgetNumber To ListOfNamesArray(ArraySize(ListOfNamesArray()))\ButtonGadgetNumber
Debug "In List"
For o = 0 To ArraySize(ListOfNamesArray())
If ListOfNamesArray(o)\ButtonGadgetNumber = EventGadget()
Break
EndIf
Next
MakeStuffHappenHere(o)
EndSelect
EndSelect
ForEver
doesn't work
The array is populated dynamically throughout the rest of the program... emptied, resized etc... would this be causing it to not play ball? The gadgets are all freed before the array is played about with
Any pointers? I use similar code on some other buttons that are created once... but not changed like I do here
Edit:
I have also tried:
Code:
Select EventGadget()
Default
For q = 0 To ArraySize(ListOfNamesArray())
If ListOfNamesArray(q)\ButtonGadgetNumber = EventGadget()
Break
EndIf
Next
MakeStuffHappenHere(q)
...but that also seems to trigger sometimes if you use the mouse scroll wheel on the scroll area