SetActiveGadget to nothing
- captain_skank
- Enthusiast
- Posts: 639
- Joined: Fri Oct 06, 2006 3:57 pm
- Location: England
SetActiveGadget to nothing
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
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
Just don't call SetActiveGadget().captain_skank wrote:Is there a way to set the active gadget to nothing ??

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 

- captain_skank
- Enthusiast
- Posts: 639
- Joined: Fri Oct 06, 2006 3:57 pm
- Location: England
Re: SetActiveGadget to nothing
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
never mind, misread post, removed this
The world and human nature was screwed up before I was born. It's not my fault and I'm just stuck with trying to deal with the mess left behind, so don't blame me.
Re: SetActiveGadget to nothing
Code: Select all
IsGadget(#gadget)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: SetActiveGadget to nothing
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.captain_skank wrote:...gadget not initialised as the original gadget no longer exist's
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 

- captain_skank
- Enthusiast
- Posts: 639
- Joined: Fri Oct 06, 2006 3:57 pm
- Location: England
Re: SetActiveGadget to nothing
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-doneTI-994A wrote: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.captain_skank wrote:...gadget not initialised as the original gadget no longer exist's

Re: SetActiveGadget to nothing
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.captain_skank wrote:...as the program returns to the main form the gadget is still highlighted...
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 

Re: SetActiveGadget to nothing
Ugly but working:
Create a TextGadget() HideGadget() and set this gadget active.
Bernd
Create a TextGadget() HideGadget() and set this gadget active.
Bernd
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: SetActiveGadget to nothing
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
BERESHEIT
-
- Enthusiast
- Posts: 443
- Joined: Sun Apr 06, 2008 12:54 pm
- Location: Brisbane, Qld, Australia
- Contact:
Re: SetActiveGadget to nothing
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.infratec wrote:Create a TextGadget() HideGadget() and set this gadget active.
Re: SetActiveGadget to nothing
Good one, netmaestro. Seems to work.netmaestro wrote:Code: Select all
SetActiveGadget(-1)

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 

Re: SetActiveGadget to nothing
Code: Select all
SetActiveGadget(-1)
You get an error in Linux.
Bernd[Error] Invalid memory access.
Re: SetActiveGadget to nothing
I'm moving it to feature request, as it can be useful to have a standard way to do it (ie: SetActiveGadget(#PB_None))
- captain_skank
- Enthusiast
- Posts: 639
- Joined: Fri Oct 06, 2006 3:57 pm
- Location: England
Re: SetActiveGadget to nothing
Thanks netmaestro - never even thought about trying this - works like a charm.netmaestro wrote:Code: Select all
SetActiveGadget(-1)