AddEvent but no RemoveEvent??

LineCutter

Active Member
Licensed User
Longtime User
I'm probably missing something, but when I add a panel & some buttons, dispose of them all & then call the routines again I get the button_click sub called twice. Debugging shows that there is no detour between endsub & the first statement of the same sub.
Bug in B4PPC or in my programming??

Called from an imagebutton:
(Prefstable has 4 locations, one hardcoded as "All")
B4X:
Sub OtherButton_ButtonDown
    AddPanel("Main", "OtherPanel", 10, 10 ,225, 255)
    spacer=10
    ButtonHeight=(Otherpanel.Height-((PrefsTable.rowcount+1)*spacer))/PrefsTable.rowcount
    Buttonwidth=Otherpanel.Width-(2*spacer)
    For i = 0 To prefstable.rowcount-1
        AddButton("OtherPanel", Prefstable.cell("Location",i)&"Button",spacer,((i+1)*spacer)+(i*buttonheight),ButtonWidth, ButtonHeight,Prefstable.cell("Location",i))
        'AddEvent (Control Name, Event Name, Sub Name)
        AddEvent (Prefstable.cell("Location",i)&"Button", Click, "SetFilter")
    Next
    Otherpanel.bringtofront
End Sub
Calls this:
B4X:
Sub SetFilter
    If Sender.text="All" Then
        jobtable.Filter("Done=''")
    Else
        jobtable.Filter("Location='"&Sender.text&"'")
    End If
    jobtable.SelectCell("index",0)
    For i = 0 To prefstable.rowcount-1
        Control(Prefstable.cell("Location",i)&"Button", button).dispose
    Next
    Otherpanel.dispose
End Sub
Which repeats twice on the second call (button click) & errors because the sender doesn't exist for the second loop through the sub. Curiously, there are only 2 loops if I opt to continue after the error.
 
Top