Subject: | Re: Move to to Library
| Date: | 1 Dec 2018 12:03:35 -0400
| From: | "Kevin Zawicki" <numberjack@wi.rr.com>
| Newsgroups: | pnews.paradox-programming
|
You cannot disable default in a library at that point the library is the scope.
You need to return a logical and act on that back in the form.
Something like this:
method keyChar(var eventInfo KeyEvent)
if lib.ckPhone(eventInfo.char()) = false then
disabledefault
endif
endMethod
=====================================================
And this is the code in the library
=====================================================
method ckPhone(x string) logical
var
l logical
endvar
l = true
switch
case x >="0" and x <="9" :
case x = "-" or x = " " :
case x = "(" or x = ")" :
case x = "VK_RETURN" :
case x = "VK_TAB" :
otherwise : l = false
endSwitch
return l
I would also put these keys to trap in an array and test the array.
You can streamline this code quit a bit.
------------------------
"Kevin Baker" <shcsbaker@gmail.com> wrote:
>Hi Everyone,
>
>In a phone field I have the following code:
>
>=====================================================
>method keyChar(var eventInfo KeyEvent)
>
>var
> curChar string
>endvar
>
>curChar = eventInfo.char()
>
>switch
> case curChar >="0" and curChar <="9" :
> case curChar = "-" or curChar = " " :
> case curChar = "(" or curChar = ")" :
> case curChar = "VK_RETURN" :
> case curChar = "VK_TAB" :
> otherwise : disableDefault
>return
>endSwitch
>endMethod
>=====================================================
>
>This works PERFECT, however, I'd like to move this code to a existing
>library (and a library I already open on init or the form). Here's the
>updated code on the form:
>
>=====================================================
>method keyChar(var eventInfo KeyEvent)
>
>lib.ckPhone(eventInfo.char())
>endMethod
>=====================================================
>
>And this is the code in the library
>=====================================================
>method ckPhone(x string)
>
>switch
> case x >="0" and x <="9" :
> case x = "-" or x = " " :
> case x = "(" or x = ")" :
> case x = "VK_RETURN" :
> case x = "VK_TAB" :
> otherwise : disableDefault return
>endSwitch
>=====================================================
>
>I'm getting a error on the disableDefault (message in status bar reads:
>Error: Cannot use EVENT statement in this context)
>
>Any ideals of how to work around this? In a nutshell, when the code is
on
>the field if the user presses any key not listed, nothing happens, no beeps,
>no error messages, which is what I need. I'm just trying to move this code
>into a library so I can reuse on other forms.
>
>Thanks,
>Kevin
>
|