I wonder if it is okay to re-create gadgets with the same ID? Some code will show best:
Code: Select all
Procedure main()
Protected win.i = OpenWindow(0, 0, 0, 600, 300, "Test",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If win.i
Protected button.i = ButtonGadget(#PB_Any, 10, 170, 200, 20, "Button")
Protected start.i = ElapsedMilliseconds()
; Re-Create the Gadget every 5 seconds
Repeat
If ElapsedMilliseconds() > start.i + 5000
FreeGadget(button.i)
If ButtonGadget(button.i, 10, 170, 200, 20, "Button") = 0
Debug "FAILED: New Gadget with ID " + Str(button.i) + " failed!"
Else
Debug "OKAY: New Gadget with ID " + Str(button.i) + " created."
EndIf
start.i = ElapsedMilliseconds()
EndIf
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
EndIf
EndProcedure
main()
Is this allowed?
If not, why? If FreeGadget() was successful, there should be no problem, right?
If yes, are the resources freed and there are really no drawbacks? Is this for all gadgets and all OS? Including WebGadget?