Page 1 of 2
SetActiveGadget to nothing
Posted: Wed Nov 19, 2014 3:09 pm
by captain_skank
Is there a way to set the active gadget to nothing ??
I'm returning to my main form from a subform, but the subform free's all the gadgets on the main form and redraws them so the original active gadget no longer exists and this is causing issues in mains event loop.
Any help appreciated.
Cheers
Re: SetActiveGadget to nothing
Posted: Wed Nov 19, 2014 3:31 pm
by TI-994A
captain_skank wrote:Is there a way to set the active gadget to nothing ??
Just don't call
SetActiveGadget().

Re: SetActiveGadget to nothing
Posted: Wed Nov 19, 2014 3:37 pm
by captain_skank
I dont have a choice, as the program returns to the main form the gadget is still highlighted and if the user clicks on this gadget again to see the subform then it throws an error saying gadget not initialised as the original gadget no longer exist's
Re: SetActiveGadget to nothing
Posted: Wed Nov 19, 2014 3:40 pm
by smacker
never mind, misread post, removed this
Re: SetActiveGadget to nothing
Posted: Wed Nov 19, 2014 3:51 pm
by ts-soft
Re: SetActiveGadget to nothing
Posted: Wed Nov 19, 2014 4:20 pm
by TI-994A
captain_skank wrote:...gadget not initialised as the original gadget no longer exist's
One way to prevent this would be to use constants - that way, even if the gadgets are reinitialised, there would be no risk of such errors.
Re: SetActiveGadget to nothing
Posted: Wed Nov 19, 2014 4:57 pm
by captain_skank
TI-994A wrote:captain_skank wrote:...gadget not initialised as the original gadget no longer exist's
One way to prevent this would be to use constants - that way, even if the gadgets are reinitialised, there would be no risk of such errors.
True, but in this case I use a custom made table and each cell is a gadget and every time the table is 'refreshed' the gadgets are free'd and re-done

Re: SetActiveGadget to nothing
Posted: Wed Nov 19, 2014 5:27 pm
by TI-994A
captain_skank wrote:...as the program returns to the main form the gadget is still highlighted...
How is the gadget being highlighted? If the newly initialised gadget can be referenced, then perhaps there could be a way to change the active gadget in the same manner.
Re: SetActiveGadget to nothing
Posted: Wed Nov 19, 2014 7:38 pm
by infratec
Ugly but working:
Create a TextGadget() HideGadget() and set this gadget active.
Bernd
Re: SetActiveGadget to nothing
Posted: Thu Nov 20, 2014 2:52 am
by netmaestro
Gave something a try and it seems to work:
Code: Select all
OpenWindow(0,0,0,320,240,"")
StringGadget(0,10,10,200,20,"")
SetActiveGadget(0)
AddWindowTimer(0,1, 3000)
Repeat
ev=WaitWindowEvent()
If ev = #PB_Event_Timer
SetActiveGadget(-1)
RemoveWindowTimer(0, 1)
EndIf
Until ev=#PB_Event_CloseWindow
Re: SetActiveGadget to nothing
Posted: Thu Nov 20, 2014 3:27 am
by ozzie
infratec wrote:Create a TextGadget() HideGadget() and set this gadget active.
I do something similar. On all my windows I have a dummy text gadget placed off-screen, but I don't disable the gadget. This is the first gadget created in each window so by default focus goes to that gadget when the window is created.
Re: SetActiveGadget to nothing
Posted: Thu Nov 20, 2014 5:15 am
by TI-994A
Good one, netmaestro. Seems to work.

Re: SetActiveGadget to nothing
Posted: Thu Nov 20, 2014 7:39 am
by infratec
Is not cross platform.
You get an error in Linux.
[Error] Invalid memory access.
Bernd
Re: SetActiveGadget to nothing
Posted: Thu Nov 20, 2014 9:30 am
by Fred
I'm moving it to feature request, as it can be useful to have a standard way to do it (ie: SetActiveGadget(#PB_None))
Re: SetActiveGadget to nothing
Posted: Thu Nov 20, 2014 10:12 am
by captain_skank
Thanks netmaestro - never even thought about trying this - works like a charm.