Closed Thread
Results 1 to 5 of 5

Thread: how to 'test' entered letter.

  1. #1
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    how to 'test' entered letter.

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    alienkinetics's Avatar
    alienkinetics is offline Programmer
    Join Date
    Feb 2010
    Location
    Australia
    Posts
    154
    Rep Power
    0

    Re: how to 'test' entered letter.

    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;

  4. #3
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: how to 'test' entered letter.

    Quote Originally Posted by alienkinetics View Post
    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;
    Thanks

  5. #4
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: how to 'test' entered letter.

    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

  6. #5
    alienkinetics's Avatar
    alienkinetics is offline Programmer
    Join Date
    Feb 2010
    Location
    Australia
    Posts
    154
    Rep Power
    0

    Re: how to 'test' entered letter.

    O, forgot. Sorry. Try this to include the special codes:

    Code:
    ['a'..'z', 'A'..'Z', #1..#31]
    If you ever need the code to a key press, add this code:

    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

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 03-04-2011, 02:33 PM
  2. Replies: 7
    Last Post: 10-08-2010, 05:39 PM
  3. How to delete the last digit entered?
    By organizedchaos in forum Java Help
    Replies: 5
    Last Post: 08-09-2010, 12:03 PM
  4. Replies: 9
    Last Post: 12-27-2008, 02:15 AM
  5. Cap only first letter
    By Chan in forum C# Programming
    Replies: 5
    Last Post: 08-19-2006, 03:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts