Microsoft KB Archive/193292

= BUG: Commandbutton.SetFocus in Form Init Sets Default = .T. =

Article ID: 193292

Article Last Modified on 3/7/2005

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 3.0b for Macintosh

-



This article was previously published under Q193292



SYMPTOMS
You have created a form that contains a command button. The command button's Default property is set to .F. In the form Init method, you call the SetFocus method of the command button. When the form displays, the Default property of the command button is set to .T. and the command button becomes the default button.



RESOLUTION
Set the Default property of the Commandbutton to .F. after calling the SetFocus in the Init method.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.



Steps to Reproduce Behavior
  Run the following code from a program (.prg) file: PUBLIC oform1 oform1=CREATEOBJECT("form1") oform1.SHOW RETURN

DEFINE CLASS form1 AS FORM AUTOCENTER = .T.        HEIGHT = 408 WIDTH = 389 CAPTION = "Form1" NAME = "Form1"

ADD OBJECT text1 AS TEXTBOX WITH ; HEIGHT = 23, ; LEFT = 108, ; TOP = 48, ; WIDTH = 100, ; NAME = "Text1"

ADD OBJECT command1 AS COMMANDBUTTON WITH ; TOP = 216, ; LEFT = 120, ; HEIGHT = 27, ; WIDTH = 84, ; CAPTION = "Command1", ; NAME = "Command1", ; TABINDEX = 1, ; DEFAULT = .F.

ADD OBJECT text2 AS TEXTBOX WITH ; HEIGHT = 23, ; LEFT = 108, ; TOP = 84, ; WIDTH = 100, ; NAME = "Text2"

PROCEDURE INIT * SetFocus here causes the behavior. ThisForm.Command1.SetFocus * Uncomment the following line for Work-around. * Thisform.Command1.Default = .F.        ENDPROC

PROCEDURE Command1.CLICK WAIT WINDOW PROGRAM TIMEOUT 1 ENDPROC

ENDDEFINE  Tab once to move to the first text box. Press ENTER. RESULTS: The WAIT WINDOW displays, indicating that the command button's Click event fired.

Workaround
To demonstrate the workaround, uncomment the line of code that sets the Default property of the Commandbutton to .F.

NOTE: In Visual FoxPro for the Macintosh, KEYCOMP must be set to WINDOWS for the behavior described in this article to occur.

Keywords: kbbug kbnofix kbcontainer kbctrl KB193292

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.