So I have an edit box, and I type some letters in. I want a live detector to test if the letters entered are letters or not. If it isn't a letter, I want it to display an error message.
I used editbox.text, but I realise that this tests the WHOLE box, rather than the currently entered character. I can't really test the 'last' letter, since I can input chars into the middle.
And I would rather not test the whole text everytime, letter by letter, since that is inefficient. SO I was just wondering if there is a function, or an easier way to do this?
Thanks
Try the OnKeyPress event. This will beep if you press something not a letter
Code:procedure TFormMain.EditKeyPress(Sender: TObject; var Key: Char); begin if not(Key in ['a'..'z', 'A'..'Z']) then begin Beep; Key := #0; end; end;
Um...bit of a problem...
since i did a..z and A..Z, I can't delete what I have done with backspace. I guess its because Backspace is not part of a..z and A..Z? So how would I fix this?
The strange thing is that 'Delete' works, but not backspace...hmmm.
And that beep sound is awesome, are there anymore?
Thanks
O, forgot. Sorry. Try this to include the special codes:
If you ever need the code to a key press, add this code:Code:['a'..'z', 'A'..'Z', #1..#31]
The Beep sound is the system default. ie: What the user selected. There is the function PlaySound() in the MMSystem unit which will play some more sounds.Code:ShowMessage(IntToStr(Ord(Key)));
Enumerating and Playing System Sounds from Delphi code
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks