The following has a few calls to library functions which you don't have, but
other than that handles most situations, including correct behaviour if the
text in the field is selected.
Obviously you should stick this code in your event loop, after checking for
the right event type, and chacking that the correct field has the focus.
Let me know if you find this useful, or find any bugs in the code... 8-)
// Only allow 0-9, "-", ".", and chr(8) (backspace)
if (event->data.keyDown.chr < '0' || event->data.keyDown.chr > '9') {
if (event->data.keyDown.chr == '.') {
// Only allow one decimal.
FrmFldGetText(currentForm, objID, buffer);
if (StrChr(buffer,'.')) {
handled = true;
}
}
else if (event->data.keyDown.chr == '-') {
UInt16 start;
UInt16 end;
FldGetSelection(FrmFldPtr(currentForm, objID), &start, &end);
if (start) {
handled = true;
}
else {
FrmFldGetText(currentForm, objID, buffer);
if (buffer[0] == '-' && !end) {
handled = true;
}
}
}
else if (!((TxtGlueCharAttr(event->data.keyDown.chr) & charAttrCntrl) !=
0)) { // For OS3.0 Compatibility
handled = true;
}
}
Alan
"Oliver" <[EMAIL PROTECTED]> wrote in message news:98057@palm-dev-forum...
>
> > In your keyDownEvent event handler do:
> >
> > [...]
>
> But that, of course, doesn't prevent the user from
> entering something like "1-2.3-...24----24", so you'd
> still need to write code to validate that what was
> entered is actually a valid number, i.e.,
>
> - minus character is at the beginning if used at all
> - only one decimal "point" if any at all
> - thousand separators in right place (if you want to
> support those
> ...
>
> Oliver
>
>
> __________________________________________________
> Do you Yahoo!?
> Faith Hill - Exclusive Performances, Videos & More
> http://faith.yahoo.com
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/