SetActiveGadget to nothing

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

SetActiveGadget to nothing

Post 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
User avatar
TI-994A
Addict
Addict
Posts: 2705
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: SetActiveGadget to nothing

Post by TI-994A »

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

Re: SetActiveGadget to nothing

Post 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
smacker
User
User
Posts: 55
Joined: Thu Nov 06, 2014 7:18 pm

Re: SetActiveGadget to nothing

Post by smacker »

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.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: SetActiveGadget to nothing

Post by ts-soft »

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.
Image
User avatar
TI-994A
Addict
Addict
Posts: 2705
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: SetActiveGadget to nothing

Post 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.
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 :D
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: SetActiveGadget to nothing

Post 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 :)
User avatar
TI-994A
Addict
Addict
Posts: 2705
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: SetActiveGadget to nothing

Post 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.
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 :D
infratec
Always Here
Always Here
Posts: 7588
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: SetActiveGadget to nothing

Post by infratec »

Ugly but working:

Create a TextGadget() HideGadget() and set this gadget active.

Bernd
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: SetActiveGadget to nothing

Post 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
BERESHEIT
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: SetActiveGadget to nothing

Post 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.
User avatar
TI-994A
Addict
Addict
Posts: 2705
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: SetActiveGadget to nothing

Post by TI-994A »

netmaestro wrote:

Code: Select all

    SetActiveGadget(-1)
Good one, netmaestro. Seems to work. :D
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 :D
infratec
Always Here
Always Here
Posts: 7588
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: SetActiveGadget to nothing

Post by infratec »

Code: Select all

SetActiveGadget(-1)
Is not cross platform.
You get an error in Linux.
[Error] Invalid memory access.
Bernd
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: SetActiveGadget to nothing

Post 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))
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: SetActiveGadget to nothing

Post by captain_skank »

netmaestro wrote:

Code: Select all

    SetActiveGadget(-1)
Thanks netmaestro - never even thought about trying this - works like a charm.
Post Reply