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
how to 'test' entered letter.
Started by 2710, Feb 05 2010 09:46 AM
4 replies to this topic
#1
Posted 05 February 2010 - 09:46 AM
|
|
|
#2
Posted 05 February 2010 - 11:11 AM
Try the OnKeyPress event. This will beep if you press something not a letter
procedure TFormMain.EditKeyPress(Sender: TObject; var Key: Char); begin if not(Key in ['a'..'z', 'A'..'Z']) then begin Beep; Key := #0; end; end;
#3
Posted 07 February 2010 - 03:51 AM
alienkinetics said:
Try the OnKeyPress event. This will beep if you press something not a letter
procedure TFormMain.EditKeyPress(Sender: TObject; var Key: Char);
begin
if not(Key in ['a'..'z', 'A'..'Z']) then
begin
Beep;
Key := #0;
end;
end;
Thanks :D
#4
Posted 07 February 2010 - 03:57 AM
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? :P
Thanks
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? :P
Thanks
#5
Posted 07 February 2010 - 05:33 AM
O, forgot. Sorry. Try this to include the special codes:
If you ever need the code to a key press, add this code:
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.
Enumerating and Playing System Sounds from Delphi code
['a'..'z', 'A'..'Z', #1..#31]
If you ever need the code to a key press, add this code:
ShowMessage(IntToStr(Ord(Key)));
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.
Enumerating and Playing System Sounds from Delphi code


Sign In
Create Account


Back to top









