Fred, I was wondering if perhaps a future release of PureBasic could automatically
allocate gadget numbers, so that we can use constants to refer to them? What I was
thinking of, was that if the compiler saw a constant with a name starting with,
for example, #gad, then it could increment an internal counter and allocate that
number to that gadget/menu item/etc. See the following example routines to see
what I mean. Is this sort of idea feasible? It would save us having to renumber
our gadget constants if we add/remove gadgets during editing...
Code: Select all
[b]; Current method of allocating gadget numbers (user must do it).[/b]
If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"Test")
CreateGadgetList(WindowID())
#Button1=1 ; Proposed method means this line won't be needed.
#Button2=2 ; Proposed method means this line won't be needed.
ButtonGadget(#Button1,20,20,50,25,"button1")
ButtonGadget(#Button2,20,50,50,25,"button2")
Repeat
ev=WaitWindowEvent()
Until ev=#PB_EventCloseWindow
EndIf
Code: Select all
[b]; Proposed method of allocating gadget numbers (compiler does it).[/b]
If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"Test")
CreateGadgetList(WindowID())
; Compiler sees [b]#gad[/b] prefix in constants, and allocates an internal number.
ButtonGadget([b]#gad[/b]Button1,20,20,50,25,"button1")
ButtonGadget([b]#gad[/b]Button2,20,50,50,25,"button2")
Repeat
ev=WaitWindowEvent()
Until ev=#PB_EventCloseWindow
EndIf
PB - Registered PureBasic Coder
Edited by - PB on 02 July 2002 11:13:02