Page 1 of 1

Only #PB_Any works

Posted: Thu Oct 23, 2025 4:43 am
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

Re: Only #PB_Any works

Posted: Thu Oct 23, 2025 5:02 am
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

Re: Only #PB_Any works

Posted: Thu Oct 23, 2025 8:33 am
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 !

Re: Only #PB_Any works

Posted: Thu Oct 23, 2025 8:39 am
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

Re: Only #PB_Any works

Posted: Thu Oct 23, 2025 9:08 am
by Mindphazer
If you have a lot of gadgets, it's (in my humble opinion) easier to use constants