Editing a TextField

Greetings folks -

Using Xojo 2019 R3.1

Somehow, this used to be a lot easier but now I am lost. I have a simple one-line TextField were I would like to do the following (on all 3 major desktop platforms):

  1. Allow entry only of number and ASCII upper/lower case characters. No control characters and no symbols.

  2. Want to be able to do backspace and delete as well as right/left scroll of the insertion point with character entries and bs/del operations at the insertion point.

I have been unable to find any up-to-date examples. Is this task too easy for examples? Seems pretty fundamental to me yet its turning into something far more difficult than it feels like it ought to be.

[edit] Example: If my memory serves me right, and it might not, you used to just be able to write a BS at the insertion point and a character would magically disappear. That no longer seems to be happening. If so, it appears to require the addition of right() or left() operations, which adds to the complexity of the management of the TextField. And then you need to know where the insertion point is, adding yet more complexity. [/edit]

Many thanks
Jim Wagner
Oregon Research Electronics

In KeyDown, you should be able to just return False for the allowed keys - A-Z, Delete, Backspace, Left arrow, Right arrow - and return True for everything else.

Thanks, Tim -

But, the documentation warns that the character at keyup might not be the same as the one detected at keydown. Yes, that is what the documentation says right now. I’m not sure how this would happen, but …


Unless you are implementing KeyUp, it doesn’t matter. Given your description, you shouldn’t have to.