Page 1 of 1

4.50 : #PB_EventType_Focus and #PB_EventType_LostFocus ???

Posted: Mon Sep 06, 2010 12:03 am
by Seldon
I'm having a weird behaviour under 4.50 (just installed) with #PB_EventType_Focus and #PB_EventType_LostFocus events. It seems I get such events for gadgets whose window has been closed (causing invalid object access errors as the window doesn't exist anymore).

Here it is a sample, open the child window (click the 'OPEN' button on the main window) and then press 'ESC' (or the window close button). This worked fine under 4.41... :? It only works fine if you press the 'CLOSE' button on the child window as (I think) the #PB_EventType_Focus and #PB_EventType_LostFocus events are then processed.

Code: Select all

Enumeration
#ID_FORM_MAIN
  #ID_BUTTON_open_child_window
  
#ID_FORM_child_window
  #ID_TEXTBOX_test_1
  #ID_TEXTBOX_test_2
  #ID_BUTTON_close
  #ID_STATUSSTRIP_child_window
EndEnumeration

H_wnd=OpenWindow(#ID_FORM_MAIN,0,0,320,256,"Test",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget)
If H_wnd
  ButtonGadget(#ID_BUTTON_open_child_window,9,9,90,30,"OPEN")
EndIf

Repeat
  ID_EVENT=WaitWindowEvent()
  ID_WINDOW=EventWindow()
  
  If ID_WINDOW=#ID_FORM_MAIN

    Select ID_EVENT    
        
      Case #PB_Event_Gadget
        
        Select EventGadget()
            
          Case #ID_BUTTON_open_child_window
            If OpenWindow(#ID_FORM_child_window,0,0,240,180,"CHILD WINDOW",#PB_Window_Tool|#PB_Window_TitleBar|#PB_Window_SystemMenu|#PB_Window_WindowCentered,WindowID(#ID_FORM_MAIN))
              If CreateStatusBar(#ID_STATUSSTRIP_child_window,WindowID(#ID_FORM_child_window))
                AddStatusBarField(#PB_Ignore) 
              EndIf              
              StringGadget(#ID_TEXTBOX_test_1,9,9,90,21,"")
              StringGadget(#ID_TEXTBOX_test_2,9,60,90,21,"")              
              ButtonGadget(#ID_BUTTON_close,9,120,90,30,"CLOSE")
              AddKeyboardShortcut(#ID_FORM_child_window,#PB_Shortcut_Escape,1)
              SetActiveGadget(#ID_TEXTBOX_test_1)
            EndIf
            
        EndSelect
        
      Case #PB_Event_CloseWindow
        End
        
    EndSelect
    
  ElseIf ID_WINDOW=#ID_FORM_child_window
    
    Select ID_EVENT    
        
      Case #PB_Event_Gadget
        
        Select EventGadget()
                       
          Case #ID_TEXTBOX_test_1
            Select EventType()
                
              Case #PB_EventType_Focus
                StatusBarText(#ID_STATUSSTRIP_child_window,0,"#ID_TEXTBOX_test_1")    
                
              Case #PB_EventType_LostFocus
                StatusBarText(#ID_STATUSSTRIP_child_window,0,"")

            EndSelect
           
          Case #ID_TEXTBOX_test_2
            Select EventType()
                
              Case #PB_EventType_Focus
                StatusBarText(#ID_STATUSSTRIP_child_window,0,"#ID_TEXTBOX_test_2") 
                
              Case #PB_EventType_LostFocus
                StatusBarText(#ID_STATUSSTRIP_child_window,0,"")                

            EndSelect
            
          Case #ID_BUTTON_close
            RemoveKeyboardShortcut(#ID_FORM_child_window,#PB_Shortcut_Escape)
            CloseWindow(#ID_FORM_child_window)
            
        EndSelect
        
      Case #PB_Event_Menu
        Select EventMenu()

          Case 1  ; 'ESC'
            RemoveKeyboardShortcut(#ID_FORM_child_window,#PB_Shortcut_Escape)
            CloseWindow(#ID_FORM_child_window)            
        EndSelect
        
      Case #PB_Event_CloseWindow
        RemoveKeyboardShortcut(#ID_FORM_child_window,#PB_Shortcut_Escape)
        CloseWindow(#ID_FORM_child_window)
    EndSelect

  EndIf
  
ForEver
Thanks for any hints ! :)

Re: 4.50 : #PB_EventType_Focus and #PB_EventType_LostFocus ?

Posted: Mon Sep 06, 2010 10:09 am
by Seldon
Ehi, may you confirm the same behaviour (also guys from PB staff please) ? My PC has Windows-XP-Home Edition (SP3). Later I can try on Windows-7. The weird thing is that the same code under 4.41 works perfectly (I still have the previous version on the same computer).

Re: 4.50 : #PB_EventType_Focus and #PB_EventType_LostFocus ?

Posted: Mon Sep 06, 2010 2:08 pm
by Demivec
I can confirm for PB 4.51 RC2 Windows XP Home Edition SP3.

Re: 4.50 : #PB_EventType_Focus and #PB_EventType_LostFocus ?

Posted: Mon Sep 06, 2010 2:25 pm
by Seldon
Demivec wrote:I can confirm for PB 4.51 RC2 Windows XP Home Edition SP3.
Thanks for your time ! So... can this be considered a bug ??? I don't think that code is doing something wrong. It seems '#PB_EventType_Focus' and '#PB_EventType_LostFocus' events are triggered after '#PB_Event_CloseWindow' and '#PB_Event_Menu' (key press) events...

Re: 4.50 : #PB_EventType_Focus and #PB_EventType_LostFocus ?

Posted: Sun Sep 19, 2010 9:44 am
by Seldon
I've opened a new thread in the bug section of the forum, anyway a possible and simple work-around would be this :

Code: Select all

Case #PB_EventType_LostFocus
  If IsWindow((#ID_FORM_child_window)
    StatusBarText(#ID_STATUSSTRIP_child_window,0,"")
  EndIf
But I still hope all will work again as it did before 4.5x !

PS: It seems to me 4.5x is a very buggy version... I don't know maybe it's just my impression... :?