Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataSession problem related to function keys - Is this a
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00403617
Message ID:
00403698
Views:
13
>I'm thinking this is a bug because if I call the PRG using a button instead of F2, only the datasession of Form B gets changed as I expected. Or if the F2 key invokes a method of Form B instead of a PRG, it also works as expected and only changes Form B. It's only when I use the combination of a function key calling a PRG that both datasessions get changed.
>

The problem is that OKLs run outside the scope of the form; if you trapped the Keystroke in the Keypress event of the form, then it would fire in the scope of the form. If you want to change the scope of the active form from an OKL, then you need to change the datasession of the form by:
IF TYPE('_SCREEN.ActiveForm') = 'O' AND UPPER(_SCREEN.ActiveForm.BaseClass) = 'FORM'
   IF _Screen.ActiveForm.DataSession = 2
      _Screen.ActiveForm.DataSessionID = <i>whatever</i>
   ENDIF
ENDIF

In order to operate in the context of the Active Form, add a custom class to your Form Parent class.

PROCEDURE DoJunkPrg
   DO JunkPrg
ENDPROC

Now, your OKL calls:

ON KEY F2 DO DoFormJunkPrg

*DoFormJunkPrg.PRG
IF PEMSTATUS('_SCREEN.ActiveForm.DoJunkPrg',3) = 'Method'
   _Screen.ActiveForm.DoJunkPrg()
ENDIF

Or to generalize for lots of OKLs

PROCEDURE DoJunk
   LPARAMETER cPrgName
   DO (cPrgName)
ENDPROC

ON KEY F2 DO DoFormJunk WITH 'JunkPrg'

*DoFormJunkPrg.PRG
LPARAMETER cWhatToDo
IF PEMSTATUS('_SCREEN.ActiveForm.DoJunk',3) = 'Method'
   _Screen.ActiveForm.DoJunkPrg(cWhatToDo)
ENDIF
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform