Only #PB_Any works

Just starting out? Need help? Post your questions and find answers here.
RogerTunnicliffe
User
User
Posts: 18
Joined: Fri Oct 17, 2025 10:10 pm

Only #PB_Any works

Post by RogerTunnicliffe »

Why does #PB_Any used for Editor_1 work while the SetGadgetColor for Editor_2 (#G_Editor2) and Editor_3 (1) fail with the error
"The specified gadget is not initialised ??

Code: Select all

Enumeration Stuff
  #G_Editor2
EndEnumeration

OpenWindow(0, 0, 0, 640, 240, "Demo", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

  Editor_1 = EditorGadget(#PB_Any, 10, 10, 600, 100)
    SetGadgetColor(Editor_1, #PB_Gadget_BackColor, #Black)
    SetGadgetColor(Editor_1, #PB_Gadget_FrontColor, #White)

  Editor_2 = EditorGadget(#G_Editor2, 10, 120, 600, 100)
    SetGadgetColor(Editor_2, #PB_Gadget_BackColor, #Black)
    SetGadgetColor(Editor_2, #PB_Gadget_FrontColor, #White)
  Editor_3 = EditorGadget(1, 10, 120, 600, 100)
    SetGadgetColor(Editor_2, #PB_Gadget_BackColor, #Black)
    SetGadgetColor(Editor_2, #PB_Gadget_FrontColor, #White)
  
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
TI-994A
Addict
Addict
Posts: 2749
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Only #PB_Any works

Post by TI-994A »

For gadget assignments, the PureBasic #PB_Any flag works only for dynamic gadget numbering. If a gadget number is specified, that would be the gadget number and not the returned value.

Code: Select all

Enumeration Stuff
  #G_Editor2
EndEnumeration

OpenWindow(0, 0, 0, 640, 240, "Demo", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

Editor_1 = EditorGadget(#PB_Any, 10, 10, 600, 100)   ; Editor_1 is the gadget number
SetGadgetColor(Editor_1, #PB_Gadget_BackColor, #Black)
SetGadgetColor(Editor_1, #PB_Gadget_FrontColor, #White)

EditorGadget(#G_Editor2, 10, 120, 600, 100)   ; #G_Editor2 is the gadget number
SetGadgetColor(#G_Editor2, #PB_Gadget_BackColor, #Black)
SetGadgetColor(#G_Editor2, #PB_Gadget_FrontColor, #Green)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
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
Mindphazer
Enthusiast
Enthusiast
Posts: 486
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Only #PB_Any works

Post by Mindphazer »

RogerTunnicliffe wrote: Thu Oct 23, 2025 4:43 am

Code: Select all

  Editor_2 = EditorGadget(#G_Editor2, 10, 120, 600, 100)
   
You can't do that
Either you assign a gadgetnumber to a variable using #PB_any
Either you use your gadget with a defined constant
But not both !
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
RogerTunnicliffe
User
User
Posts: 18
Joined: Fri Oct 17, 2025 10:10 pm

Re: Only #PB_Any works

Post by RogerTunnicliffe »

Oh I see, thx

I think it makes more sense syntactically to number it yourself, but maybe that's just me.

Thx again
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 486
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Only #PB_Any works

Post by Mindphazer »

If you have a lot of gadgets, it's (in my humble opinion) easier to use constants
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Post Reply