Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Difference in clicking
Message
From
15/02/2016 14:29:25
 
 
To
15/02/2016 09:55:46
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7
OS:
Windows 7
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01631466
Message ID:
01631502
Views:
59
>There appears to be a difference in physically clicking a button with the mouse, and doing it programmatically, as in thisform.thatbutton.click. Can anyone please explain this to me?
>
>I have a textbox that a search string is typed into. To make it more convenient for the user, so they don't have to actually use the mouse, I have the following in the KeyPress method:
>
>IF nKeyCode=13 &&the 'enter' key
>	thisform._searchcmd.Click
>ENDIF
>
>
>The code in thisform._searchcmd.click is accessed, and run, but the cursor holding the SQL Select(ed) data is empty. Physically click the _searchcmd button, and the data is there...

Others have already pointed out that it's probably cleaner for both your code above and the .Click() code it references to point to a new method.

I don't know whether it will help in this case, but whenever you're modifying event handlers such as .KeyPress( ) it's a good idea to keep the default action in mind. That is, code you put in these events/methods REPLACES the action that would normally occur UNLESS you add in DODEFAULT( ). Most of the time you want the default action to occur, but you want to add something extra to it. So in your case you would probably want something like:
LPARAMETERS nKeyCode, nShiftAltCtrl

=DODEFAULT( nKeyCode, nShiftAltCtrl )
* The default action for this event requires the two parameters. So, if you want to
* manually run it, you must pass them in as parameters to DODEFAULT( )
* For events/methods that don't have native parameters, you can just use DODEFAULT( ) without parameters

IF nKeyCode=13 &&the 'enter' key
	thisform._searchcmd.Click
ENDIF

...etc
Making sure you properly call DODEFAULT( ) is especially important with tricky controls such as combo boxes. I find in practice I want the default action to occur before my extra code, but I have had occasion to call it after my code (i.e. I want a form of "pre-processing" before the event). And also on some occasions I have wanted to completely override the default action so I explicitly do not include DODEFAULT( ).

Bottom line, most of the time you will want to include DODEFAULT( ) in event handler code, and usually before your own custom code.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Reply
Map
View

Click here to load this message in the networking platform