Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Did Grid.SetFocus( ) Behavior Change in VFP7?
Message
From
07/09/2001 16:22:35
 
 
To
06/09/2001 13:36:46
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00553269
Message ID:
00554062
Views:
15
>>
In VFP7, the SetFocus( ) method seems to be changing the selected ALIAS.
<<

I'm not seeing what you describe. First of all, whenever a grid has focus, it's recordsource should become the selected workarea. This is how VFP6 works as well. Using the code below, I see the same behavior in VFP6 and VFP7, which is that the grid recordsource becomes selected after any user code in the highest parentclass containing code is executed.

Here is my code. It creates a grid class and a form containing an instance of the class. By default there is 1 level of subclassing, but you can uncomment the 2nd CREATE CLASS command, and change the NewObject() line from grd to grd1 if you want to add another level.

Run the code, and click the button, then look in the debug output window.

LOCAL aobj[1], xx
#define CRLF CHR(13)+CHR(10)

DEBUG
DEBUGOUT ""
CLOSE DATABASES ALL
CLEAR CLASS grd

* Make the grid class
DELETE FILE testxx.vc?
CREATE CLASS grd OF testxx.vcx as grid nowa
=ASELOBJ(aobj,1)
xx = aobj[1]
lcMethodCode =[DEBUGOUT TIME()+' '+ ALIAS()+' '+PROGRAM()]+CRLF+ ;
[* nodefault]
xx.writemethod('setfocus',lcMethodCode )
KEYBOARD 'Y' CLEAR
RELEASE WINDOW 'Class Designer'

* make another grid class based on the one above
*!* CREATE CLASS grd1 OF testxx.vcx as grd FROM testxx.vcx nowa
*!* =ASELOBJ(aobj,1)
*!* xx = aobj[1]
*!* lcMethodCode = [DEBUGOUT TIME()+' '+ ALIAS()+' '+PROGRAM()]+CRLF+ ;
*!* [DODEFAULT()]
*!* xx.writemethod('setfocus',lcMethodCode )
*!* KEYBOARD 'Y' CLEAR
*!* RELEASE WINDOW 'Class Designer'

*Make the form
DELETE FILE testxx.sc?
CREATE FORM testxx NOWAIT
* DE setup
=ASELOBJ(aobj,2)
xx = aobj[1]
xx.addobject('cursor1','cursor')
xx.cursor1.cursorsource = 'customer'
xx.cursor1.database= HOME(2)+'data\testdata.dbc'
xx.addobject('cursor2','cursor')
xx.cursor2.cursorsource = 'orders'
xx.cursor2.database= HOME(2)+'data\testdata.dbc'
xx.initialselectedalias = 'customer'
* add form controls
=ASELOBJ(aobj,1)
xx = aobj[1]
xx.datasession = 1
xx.autocenter = .t.
xx.addobject('txt1','textbox')
xx.txt1.controlsource = 'customer.cust_id'
xx.addobject('cmd1','commandbutton')
xx.cmd1.left = 150
lcMethodCode = [SELECT customer]+CRLF+ ;
[DEBUGOUT TIME()+' '+ ALIAS()+' '+PROGRAM()] +CRLF+ ;
[thisform.grdOrders.setfocus()]+CRLF+ ;
[DEBUGOUT TIME()+' '+ ALIAS()+' '+PROGRAM()]
xx.cmd1.WriteMethod('click',lcMethodCode )
xx.newobject('grdOrders','grd','testxx.vcx') && changing grd to grd1 adds another level
lcMethodCode = [DEBUGOUT TIME()+' '+ ALIAS()+' '+PROGRAM()+" Before"] +CRLF+ ;
[IF !DODEFAULT()]+CRLF+ ;
[ENDIF]+CRLF+ ;
[DEBUGOUT TIME()+' '+ ALIAS()+' '+PROGRAM()+" After"]+CRLF+ ;
[* grid::setfocus()]
xx.grdOrders.WriteMethod('setfocus',lcMethodCode )
xx.grdOrders.top = 40
xx.grdOrders.recordsource = 'orders'
KEYBOARD 'Y' CLEAR
RELEASE WINDOW 'Form Designer - testxx.scx'
DO FORM testxx
RETURN

In the debug output window, I get something like this, in both VFP6 and VFP7:

16:04:12 CUSTOMER FORM1.CMD1.CLICK
16:04:12 CUSTOMER FORM1.GRDORDERS.SETFOCUS Before
16:04:12 CUSTOMER GRD.SETFOCUS
16:04:12 ORDERS FORM1.GRDORDERS.SETFOCUS After
16:04:12 ORDERS FORM1.CMD1.CLICK

So the selected workarea change happens after any user code in the setfocus closest to the baseclass, in this case in grd.setfocus().

If I uncomment out the nodefault in grd.setfocus, and the grid::setfocus() in the grdorders.setfocus(), I can make the automatic changing of the selected workarea happen later.

It sounds like in your case, the selected workarea changes before the user code executes in the setfocus closest to the baseclass. I'm not seeing that. I tried with private datasession as well, with the same result. I'm guessing your exact usage is different than mine above...

Jim
Jim Saunders
Microsoft
This posting is provided “AS IS”, with no warranties, and confers no rights.
Previous
Reply
Map
View

Click here to load this message in the networking platform