Article ID: 190567
Article Last Modified on 12/11/1999
PUBLIC oForm1
oForm1=CREATEOBJECT("form1")
oForm1.Show
DEFINE CLASS Form1 AS form
AutoCenter = .T.
Height = 252
Width = 326
Name = "Form1"
ADD OBJECT Text1 AS textbox WITH ;
Height = 23, ;
Left = 36, ;
Top = 24, ;
Width = 100, ;
Name = "Text1"
ADD OBJECT Command1 AS commandbutton WITH ;
Top = 24, ;
Left = 204, ;
Height = 27, ;
Width = 84, ;
TabStop = .F., ;
Name = "Command1", ;
Default = .T.
ADD OBJECT Command2 AS commandbutton WITH ;
Top = 72, ;
Left = 204, ;
Height = 27, ;
Width = 84, ;
TabStop = .F., ;
Name = "Command2"
ADD OBJECT Edit1 AS editbox WITH ;
Height = 49, ;
Left = 48, ;
Top = 192, ;
Width = 216, ;
Name = "Edit1"
PROCEDURE Text1.LostFocus
ThisForm.Command1.default = .T.
ENDPROC
PROCEDURE Edit1.LostFocus
ThisForm.Command2.default = .T.
ENDPROC
ENDDEFINE
PUBLIC oForm1
oForm1=CREATEOBJECT("form1")
oForm1.Show
DEFINE CLASS Form1 AS form
AutoCenter = .T.
Height = 252
Width = 326
Name = "Form1"
ADD OBJECT Text1 AS textbox WITH ;
Height = 23, ;
Left = 36, ;
Top = 24, ;
Width = 100, ;
Name = "Text1"
ADD OBJECT Command1 AS commandbutton WITH ;
Top = 24, ;
Left = 204, ;
Height = 27, ;
Width = 84, ;
TabStop = .F., ;
Name = "Command1", ;
Default = .T.
ADD OBJECT Command2 AS commandbutton WITH ;
Top = 72, ;
Left = 204, ;
Height = 27, ;
Width = 84, ;
TabStop = .F., ;
Name = "Command2"
ADD OBJECT Edit1 AS editbox WITH ;
Height = 49, ;
Left = 48, ;
Top = 192, ;
Width = 216, ;
Name = "Edit1"
PROCEDURE text1.GotFocus
DoDefault()
ThisForm.Command1.default = .T.
ENDPROC
PROCEDURE edit1.GotFocus
DoDefault()
ThisForm.Command2.default = .T.
ENDPROC
ENDDEFINE
A potential workaround, which is likely to be difficult to implement, would
be to use code like the preceding code to manage your default command
buttons. Keep in mind that the intrinsic GotFocus behavior does the reset,
so the GotFocus() event for all controls, even those which do not set a
command button to default, causes the reset to occur. A workaround would
involve adding code to all control's GotFocus() method to find and store
the current default button, issue a DoDefault(), and restore the correct
default button. However, the DoDefault() function only works in Visual
FoxPro 5.0 and later versions.
LOCAL loDefaultButton, lni
WITH thisform
FOR lni = 1 to .Controlcount
IF .Controls(lni).Baseclass = 'Commandbutton' ;
and .Controls(lni).Default = .t.
loDefaultButton = .Controls(lni)
ENDIF
ENDFOR
ENDWITH
DoDefault()
IF type('loDefaultButton') = "O"
loDefaultButton.Default = .t.
ENDIF
Note that this assumes that any default command buttons are directly on the
form, and not in a non-form container such as a container or page. It fails
to find a command button not directly on the form.
Additional query words: kbVFp500abug kbOOP
Keywords: kbbug kbpending kbcode KB190567