[Solved] UnbindEvent() : Bug or not (Or i'm a bug :p)

Just starting out? Need help? Post your questions and find answers here.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

[Solved] UnbindEvent() : Bug or not (Or i'm a bug :p)

Post by falsam »

■ Just for example : If I move a window, I unbind the callback for the current window. But it does not work.

Code: Select all

Declare Start()
Declare MoveWindow()
Declare Exit()

Start()

Procedure Start()
  OpenWindow(0, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu)
  OpenWindow(1, 410, 0, 400, 300, "Test", #PB_Window_SystemMenu)
    
  ;Triggers
  BindEvent(#PB_Event_CloseWindow, @Exit())  
  BindEvent(#PB_Event_MoveWindow, @MoveWindow())
  
  Repeat : WaitWindowEvent() : ForEver
EndProcedure

Procedure MoveWindow()
  Protected Window = EventWindow()
  Debug "Move window " + Window
  UnbindEvent(#PB_Event_MoveWindow, @MoveWindow(), Window)
EndProcedure

Procedure Exit()  
  End
EndProcedure
■ The solution is to make a bind for each window.

Code: Select all

Declare Start()
Declare MoveWindow()
Declare Exit()

Start()

Procedure Start()
  OpenWindow(0, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu)
  OpenWindow(1, 410, 0, 400, 300, "Test", #PB_Window_SystemMenu)
    
  ;Triggers
  BindEvent(#PB_Event_CloseWindow, @Exit())  
  
  BindEvent(#PB_Event_MoveWindow, @MoveWindow(), 0)
  BindEvent(#PB_Event_MoveWindow, @MoveWindow(), 1)
    
  Repeat : WaitWindowEvent() : ForEver
EndProcedure

Procedure MoveWindow()
  Protected Window = EventWindow()
  Debug "Move window " + Window
  UnbindEvent(#PB_Event_MoveWindow, @MoveWindow(), Window)
EndProcedure

Procedure Exit()  
  End
EndProcedure
So: Bug or not? Thanks.
Last edited by falsam on Wed Aug 16, 2017 7:43 pm, edited 1 time in total.

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: UnbindEvent() : Bug or not (Or i'm a bug :p)

Post by User_Russian »

In my opinion this is not a bug.

Code: Select all

Declare Start()
Declare MoveWindow()
Declare Exit()

Start()

Procedure Start()
  OpenWindow(0, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu)
  OpenWindow(1, 410, 0, 400, 300, "Test", #PB_Window_SystemMenu)
    
  ;Triggers
  BindEvent(#PB_Event_CloseWindow, @Exit())  
  BindEvent(#PB_Event_MoveWindow, @MoveWindow())
  
  Repeat : WaitWindowEvent() : ForEver
EndProcedure

Procedure MoveWindow()
  Protected Window = EventWindow()
  Debug "Move window " + Window
  UnbindEvent(#PB_Event_MoveWindow, @MoveWindow())
EndProcedure

Procedure Exit()  
  End
EndProcedure
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: UnbindEvent() : Bug or not (Or i'm a bug :p)

Post by falsam »

@User_Russian : Hello. Your example removes the callback for both windows. I wanted to remove the callback when you move the window 0 and after when you move the window 1.

My debug must be
Move window 0
Move window 1
This is not the result of your code :wink:

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: UnbindEvent() : Bug or not (Or i'm a bug :p)

Post by Fred »

You can't unbind a general event for only one window. You need to register the event for each window if you plan to unbind them later

Code: Select all

Declare Start()
Declare MoveWindow()
Declare Exit()

Start()

Procedure Start()
  OpenWindow(0, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu)
  OpenWindow(1, 410, 0, 400, 300, "Test", #PB_Window_SystemMenu)
   
  ;Triggers
  BindEvent(#PB_Event_CloseWindow, @Exit()) 
  BindEvent(#PB_Event_MoveWindow, @MoveWindow(), 0)
  BindEvent(#PB_Event_MoveWindow, @MoveWindow(), 1)
 
  Repeat : WaitWindowEvent() : ForEver
EndProcedure

Procedure MoveWindow()
  Protected Window = EventWindow()
  Debug "Move window " + Window
  UnbindEvent(#PB_Event_MoveWindow, @MoveWindow(), Window)
EndProcedure

Procedure Exit() 
  End
EndProcedure
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: UnbindEvent() : Bug or not (Or i'm a bug :p)

Post by falsam »

You need to register the event for each window if you plan to unbind them later
Solved. Not a bug. Thanks Fred.

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
Post Reply