*&* CONTBUG.TXT *&* Lisa Slater Nicholls *&* To Demonstrate a problem with the *&* Container class SetFocus method *&* in VFP 5.0a, and a workaround/fix *&* for your top level container class PUBLIC oform1 oform1=CREATEOBJECT("form1") oform1.Show RETURN DEFINE CLASS form1 AS form Caption = "Container.SetFocus() is broken..." BackColor = RGB(255,0,0) ADD OBJECT command1 AS commandbutton WITH ; Top = 12, ; Left = 3, ; Caption = "CORRECT BEHAVIOR: "+; "First Control in Form Tab Order -- tab to container and watch focus" ADD OBJECT container1 AS containerclass WITH ; Top = 50, ; Left = 3, ; Height = 133, ; BorderWidth = 3, ; BackColor = RGB(0,0,255), ; BackStyle = 1 ADD OBJECT command2 AS commandbutton WITH ; Top = 200, ; Left = 3, ; Caption = "INCORRECT BEHAVIOR: "+ ; "Press to set focus to Container -- watch which button gets focus" PROCEDURE Init *&* cosmetics only for the demo, pay no attention to this code: THIS.SetAll("FontBold", .T.) THIS.SetAll("AutoSize", .T.) THIS.SetAll("AutoSize", .F.) THIS.Width = THIS.Command1.Width + 6 THIS.Container1.Width = THIS.Width - 6 THIS.Height = THIS.Command2.Top+This.Command2.Height+12 THIS.Command2.Width = THIS.Command1.Width THIS.Container1.Setall("Width", THIS.Command1.Width -20) ENDPROC PROCEDURE command2.Click *&* here's the only meaningful line of code: THISFORM.Container1.SetFocus ENDPROC ENDDEFINE DEFINE CLASS containerclass AS Container ADD OBJECT command1 AS commandbutton WITH ; Top = 12, ; Left = 10, ; TabIndex = 2, ; Caption = "First Control Dropped Into Container "+ ; "(Container.Controls(1))" ADD OBJECT command2 AS commandbutton WITH ; Top = 84, ; Left = 10, ; TabIndex = 1, ; Caption = "Control In Container Designated "+ ; "With TabIndex = 1" *&* here's the code that would work around the bug, *&* by doing what VFP should be doing internally: *&* PROC SetFocus *&* LOCAL loControl *&* FOR EACH loControl in THIS.Controls *&* IF loControl.TabIndex = 1 *&* loControl.SetFocus() *&* NODEFAULT *&* EXIT *&* ENDIF *&* ENDFOR *&* ENDPROC ENDDEFINE