4.50 : #PB_EventType_Focus and #PB_EventType_LostFocus ???
Posted: Mon Sep 06, 2010 12:03 am
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.
Thanks for any hints ! 
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...
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