General information
Category:
Forms & Form designer
I've narrowed down the problem to a reproducible test case.
In a nutshell:
1. Set focus to the grid (this makes the grid's table the current workarea).
2. User clicks a button (defocusing the grid).
3. The button sets focus to the grid, then SELECTs a different work area than the grid's. Alias() indicates success.
4. User clicks another button (probably any UI event, or even a delay would do the same thing) and Alias() has changed back to the grid's table.
It's almost like the grd.SetFocus doesn't fire right away, so it actually occurs after the SELECT of another table. When it does actually get the focus (somewhere in the bowels of the VFP runtime), it sets the workarea right back to the grid's, nullifying the explicit SELECT.
Naturally, this is a rather contrived example. The actual scenario occurred when clicking a button to add a record to the grid, then cancelling, then trying to add again.
Here's a program that demonstrates the problem:
PUBLIC otestselect
otestselect=NEWOBJECT("testselect")
otestselect.Show
RETURN
DEFINE CLASS testselect AS form
Height = 158
Width = 326
DoCreate = .T.
AutoCenter = .T.
Caption = "Test SELECT with Grid"
Name = "TestSelect"
ildetailselected = .F.
ADD OBJECT grd AS grid WITH ;
Height = 54, ;
Left = 12, ;
RowHeight = 19, ;
TabIndex = 4, ;
Top = 12, ;
Width = 198, ;
ZOrderSet = 25, ;
Name = "grd"
ADD OBJECT txtalias AS textbox WITH ;
Height = 21, ;
Left = 78, ;
ReadOnly = .T., ;
TabIndex = 5, ;
Top = 72, ;
Width = 78, ;
Name = "txtAlias"
ADD OBJECT cmdexit1 AS commandbutton WITH ;
Top = 120, ;
Left = 228, ;
Height = 30, ;
Width = 90, ;
Cancel = .T., ;
Caption = "Close", ;
TabIndex = 3, ;
Name = "Cmdexit1"
ADD OBJECT cmdtest AS commandbutton WITH ;
Top = 60, ;
Left = 228, ;
Height = 54, ;
Width = 90, ;
WordWrap = .T., ;
Caption = "Test that MASTER is selected", ;
TabIndex = 2, ;
Name = "cmdTest"
ADD OBJECT cmdmaster AS commandbutton WITH ;
Top = 12, ;
Left = 228, ;
Height = 42, ;
Width = 90, ;
WordWrap = .T., ;
Caption = "SELECT Master", ;
Default = .T., ;
TabIndex = 1, ;
Name = "cmdMaster"
ADD OBJECT txtdetailselected AS textbox WITH ;
Height = 21, ;
Left = 78, ;
ReadOnly = .T., ;
TabIndex = 6, ;
Top = 108, ;
Width = 42, ;
Name = "txtDetailSelected"
ADD OBJECT label1 AS label WITH ;
Caption = "Alias", ;
Height = 17, ;
Left = 12, ;
Top = 72, ;
Width = 40, ;
TabIndex = 7, ;
Name = "Label1"
ADD OBJECT label2 AS label WITH ;
AutoSize = .T., ;
WordWrap = .T., ;
Caption = "Should Alias() be DETAIL?", ;
Height = 47, ;
Left = 12, ;
Top = 96, ;
Width = 54, ;
TabIndex = 8, ;
Name = "Label2"
PROCEDURE Load
set safety off
create table MASTER_T free (fld1 C(1))
create table DETAIL_T free (fld1 C(1))
set safety on
ENDPROC
PROCEDURE Init
with this
select Detail_T
.ilDetailSelected = .T.
.CheckAlias()
endwith
ENDPROC
PROCEDURE checkalias
with this
.txtAlias.Value = Alias()
.txtDetailSelected.Value = .ilDetailSelected
if Alias() = "DETAIL_T" != .ilDetailSelected
MessageBox("MASTER should be selected, but isn't.")
endif
endwith
ENDPROC
PROCEDURE Unload
close tables all
delete file "MASTER_T.dbf"
delete file "DETAIL_T.dbf"
ENDPROC
PROCEDURE cmdmaster.Click
* comment this line out, and the following
* SELECT works correctly
thisForm.grd.SetFocus()
select Master_T
thisForm.ilDetailSelected = .F.
thisForm.CheckAlias()
ENDPROC
PROCEDURE cmdtest.Click
thisForm.CheckAlias()
ENDPROC
PROCEDURE cmdexit1.Click
thisForm.Release()
ENDPROC
ENDDEFINE
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only