[lazarus] calling .SetFocus - bug

Tony Maro tony at maro.net
Mon Mar 17 20:13:02 EST 2003




Sorry for the HTML but thought it best for adding my comments...



Somewhere along the line this used to work.  User clicks a button that shows some controls and then focuses the first input line.



Unfortunately it's not setting the TComboBox as focused.  Sometimes it seems to work but most of the time it doesn't.



I built my LCL with -dVerboseFocus with the hopes of tracing the focus events, and I added some of my own writeln()'s into the LCL sources...



SetActiveControl checks to see if the control is active, and decides that FActiveControl matches the control I've passed and refuses to focus it again.  Here's some output with my notes between in bold...



First, I click on BtnNewWithdrawal...



***** FORM SETACTIVECONTROL CALLED ******

**** CALLED WITH BtnNewWithdrawal

----And it can focus

TCustomForm.SetActiveControl :TFRMMAIN FActive=TRUE FActiveControl=BtnNewWithdrawal:TBUTTON

TCustomForm.SetWindowFocus :TFRMMAIN NewFocusControl=BtnNewWithdrawal:TBUTTON HndAlloc=TRUE



[TgtkObject.SetFocus] A hWnd=08A26ED0 LCLObject=BtnNewWithdrawal:TBUTTON

[TgtkObject.SetFocus] B hWnd=08A26ED0 TopLevel=08A25478 OldFocus=00000000 OldLCLParent=nil

  C  TopLevel is a gtkwindow  focus_widget=00000000 LCLParent=nil

  E taking ImplementationWidget

  G NewFocusWidget=08A26ED0

GTKFocusCB Widget=08A26ED0 1 GetFocus=00000000 LCLObject=BtnNewWithdrawal:TBUTTON

  H NewTopLevel FocusWidget=08A26ED0

  I NewTopLevel FocusWidget=08A26ED0

[TgtkObject.SetFocus] END hWnd=08A26ED0 NewFocus=08A26ED0 NewLCLParent=BtnNewWithdrawal:TBUTTON

TCustomForm.SetWindowFocus :TFRMMAIN NewFocusControl=BtnNewWithdrawal:TBUTTON HndAlloc=TRUE



[TgtkObject.SetFocus] A hWnd=08A26ED0 LCLObject=BtnNewWithdrawal:TBUTTON

[TgtkObject.SetFocus] B hWnd=08A26ED0 TopLevel=08A25478 OldFocus=08A26ED0 OldLCLParent=BtnNewWithdrawal:TBUTTON

  C  TopLevel is a gtkwindow  focus_widget=08A26ED0 LCLParent=BtnNewWithdrawal:TBUTTON

  E taking ImplementationWidget

[TgtkObject.SetFocus] END hWnd=08A26ED0 NewFocus=08A26ED0 NewLCLParent=BtnNewWithdrawal:TBUTTON



Next I make all the components visible...



****** Making controls visible *****

Calling form focuscontrol

**** FORM.FOCUSCONTROL****

***** FORM SETACTIVECONTROL CALLED ******

**** CALLED WITH BtnWithdrawalOk

----And it can focus

TCustomForm.SetActiveControl :TFRMMAIN FActive=TRUE FActiveControl=BtnWithdrawalOk:TBUTTON

TCustomForm.SetWindowFocus :TFRMMAIN NewFocusControl=BtnWithdrawalOk:TBUTTON HndAlloc=TRUE



[TgtkObject.SetFocus] A hWnd=08A3B608 LCLObject=BtnWithdrawalOk:TBUTTON

[TgtkObject.SetFocus] B hWnd=08A3B608 TopLevel=08A25478 OldFocus=08A26ED0 OldLCLParent=BtnNewWithdrawal:TBUTTON

  C  TopLevel is a gtkwindow  focus_widget=08A26ED0 LCLParent=BtnNewWithdrawal:TBUTTON

  E taking ImplementationWidget

  G NewFocusWidget=08A3B608

GTKKillFocusCB Widget=08A26ED0 0 GetFocus=08A26ED0 LCLObject=BtnNewWithdrawal:TBUTTON

GTKFocusCB Widget=08A3B608 1 GetFocus=00000000 LCLObject=BtnWithdrawalOk:TBUTTON

  H NewTopLevel FocusWidget=08A3B608

  I NewTopLevel FocusWidget=08A3B608

[TgtkObject.SetFocus] END hWnd=08A3B608 NewFocus=08A3B608 NewLCLParent=BtnWithdrawalOk:TBUTTON

Calling form focuscontrol

**** FORM.FOCUSCONTROL****

***** FORM SETACTIVECONTROL CALLED ******

**** CALLED WITH CmbWithdrawPayTo

----And it can focus

TCustomForm.SetActiveControl :TFRMMAIN FActive=TRUE FActiveControl=CmbWithdrawPayTo:TCOMBOBOX

TCustomForm.SetWindowFocus :TFRMMAIN NewFocusControl=CmbWithdrawPayTo:TCOMBOBOX HndAlloc=TRUE



[TgtkObject.SetFocus] A hWnd=08A22980 LCLObject=CmbWithdrawPayTo:TCOMBOBOX

[TgtkObject.SetFocus] B hWnd=08A22980 TopLevel=08A25478 OldFocus=08A3B608 OldLCLParent=BtnWithdrawalOk:TBUTTON

  C  TopLevel is a gtkwindow  focus_widget=08A3B608 LCLParent=BtnWithdrawalOk:TBUTTON

  D taking gtkcombo entry

  G NewFocusWidget=08A22A70

GTKKillFocusCB Widget=08A3B608 0 GetFocus=08A3B608 LCLObject=BtnWithdrawalOk:TBUTTON

GTKFocusCB Widget=08A22A70 1 GetFocus=00000000 LCLObject=nil

  H NewTopLevel FocusWidget=08A22A70

  I NewTopLevel FocusWidget=08A22A70

[TgtkObject.SetFocus] END hWnd=08A22980 NewFocus=08A22980 NewLCLParent=CmbWithdrawPayTo:TCOMBOBOX



You can see that CmbWithdrawPayTo is currently focused... I think.  (Yes, it really is already focused by chance.)  Next I call CmbWithdrawPayTo.SetFocus;



****** SETTING FOCUS ******

Calling form focuscontrol

**** FORM.FOCUSCONTROL****

***** FORM SETACTIVECONTROL CALLED ******

Already FOCUSED!



Above, the form has correctly identified the control as already focused.  This time worked.... but wait!

Now, I click cancel to make the control be hidden again.  Why does it KillFocus a NIL object?



GTKKillFocusCB Widget=08A22A70 0 GetFocus=08A22980 LCLObject=nil

GTKFocusCB Widget=08A3B650 1 GetFocus=00000000 LCLObject=BtnWithdrawalCancel:TBUTTON

GTKKillFocusCB Widget=08A3B650 0 GetFocus=08A3B650 LCLObject=BtnWithdrawalCancel:TBUTTON

GTKFocusCB Widget=08A26ED0 1 GetFocus=00000000 LCLObject=BtnNewWithdrawal:TBUTTON



Currently nothing is focused.  All controls involved were just hidden, and the GTK form shows nothing focused.

And again I click to make them visible, by clicking BtnNewWithdrawal...



****** Making controls visible *****

GTKKillFocusCB Widget=08A26ED0 0 GetFocus=08A26ED0 LCLObject=BtnNewWithdrawal:TBUTTON

Calling form focuscontrol

**** FORM.FOCUSCONTROL****

***** FORM SETACTIVECONTROL CALLED ******

Already FOCUSED!



So now I call the setfocus method and here's what happens...



****** SETTING FOCUS ******

Calling form focuscontrol

**** FORM.FOCUSCONTROL****

***** FORM SETACTIVECONTROL CALLED ******

Already FOCUSED!



Ooops.  Actually NOTHING has focus here, except maybe the form.  Certainly none of the controls on the form are focused.  If you start typing, nothing happens.  So I click inside the combobox to focus it and...



GTKFocusCB Widget=08A22A70 1 GetFocus=00000000 LCLObject=nil



MMmm... LCLObject=nil?  Okay... let's hit cancel again to hide the controls.



GTKKillFocusCB Widget=08A22A70 0 GetFocus=08A22980 LCLObject=nil

GTKFocusCB Widget=08A3B650 1 GetFocus=00000000 LCLObject=BtnWithdrawalCancel:TBUTTON

TCustomForm.WMShowWindow A :TFRMMAIN fsShowing in FFormState=FALSE Message.Show=FALSE FActiveControl=CmbWithdrawPayTo:TCOMBOBOX HandleAllocated=TRUE

GTKKillFocusCB Widget=08A3B650 0 GetFocus=08A3B650 LCLObject=BtnWithdrawalCancel:TBUTTON







Thanks,





-- 
Tony Maro
tony at maro.net
http://tony.maro.net/

Check out my software "CheckBook Tracker"
A GPL (free) replacement for Microsoft Money!










More information about the Lazarus mailing list