Bind function

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User_Russian
Addict
Addict
Posts: 1520
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Bind function

Post by User_Russian »

I believe that in the function BindMenuEvent() should be a location parameter:

Code: Select all

BindMenuEvent(#Menu, @Callback() [, MenuItem])
If the MenuItem is not specified, then the Callback procedure is called for each menu item #Menu.
Callback procedure must include an argument MenuItem.

Code: Select all

Procedure Callback(MenuItem)
  
EndProcedure
But it would be nice if the Callback procedure would contain all the parameters Bind-function (other than the address Callback-procedure).Otherwise it will be difficult to assign a single procedure for the treatment of multiple events. For example, the procedure for appointing a few gadgets.

Code: Select all

Procedure Callback()
  Debug "Click"
EndProcedure

; Shows possible flags of ButtonGadget in action...
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
  ButtonGadget(1, 10, 40, 200, 20, "Left Button", #PB_Button_Left)
  ButtonGadget(2, 10, 70, 200, 20, "Right Button", #PB_Button_Right)
  ButtonGadget(3, 10,100, 200, 60, "Multi-line Button  (longer text gets automatically wrapped)", 
               #PB_Button_MultiLine)
  ButtonGadget(4, 10,170, 200, 20, "Toggle Button", #PB_Button_Toggle)
  
  For i=0 To 4
    BindGadgetEvent(i, @Callback())
  Next i
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
How to find out which gadget event occurred?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Bind function

Post by ts-soft »

You can use the same functions as in a normal eventloop!
Example:

Code: Select all

Procedure Callback()
  Protected MenuItem = EventMenu()
 
EndProcedure 
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
Post Reply