+ Reply to Thread
Results 1 to 5 of 5

Thread: how to 'test' entered letter.

  1. #1
    Learning Programmer 2710 is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    97

    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. #2
    Programmer alienkinetics has a little shameless behaviour in the past alienkinetics's Avatar
    Join Date
    Feb 2010
    Location
    Australia
    Posts
    154

    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;

  3. #3
    Learning Programmer 2710 is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    97

    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

  4. #4
    Learning Programmer 2710 is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    97

    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

  5. #5
    Programmer alienkinetics has a little shameless behaviour in the past alienkinetics's Avatar
    Join Date
    Feb 2010
    Location
    Australia
    Posts
    154

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Test Soon Development: a case study
    By Kernel in forum News
    Replies: 0
    Last Post: 01-03-2010, 12:10 PM
  2. Error in sys.excepthook
    By random guy in forum Python
    Replies: 2
    Last Post: 12-03-2009, 09:30 PM
  3. Replies: 0
    Last Post: 06-07-2009, 09:30 AM
  4. letter counter - C function !
    By sharonf in forum C and C++
    Replies: 10
    Last Post: 01-21-2009, 04:01 AM
  5. Test Automation Brain Dump
    By Kernel in forum News
    Replies: 0
    Last Post: 10-17-2008, 07:31 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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