Solved

Edit boxes 'n' case statements.

Posted on 1998-11-21
6
126 Views
Last Modified: 2010-04-04
I need a simple case statement for locking out everything but letters on an edit box's key-press. It's real easy but i've forgotten. PLEASE HELP ME!!!
0
Comment
Question by:Mr_Plasmo
6 Comments
 
LVL 3

Expert Comment

by:philipleighs
ID: 1347492
I the KeyDown event, type:

case Key of
VK_A..VK_Z:
   begin
       //do nothing to allow key to be typed
   end;
else
    begin
          //Next line will prevent char allearing in edit box
         Key := 0;
    end;
end;


There you have it. If you don't like windows VK_ constants, you can replace it with Ord('A')..Ord('Z')

Cheers,
Phil.

0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1347493
This doesn't work.  You would probably have to declare a new class and use the WM_KEYDOWN message.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1347494
hi Mr_Plasmo,

that's no case-statement, but this is a simple solution to allow only letters,

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
const validchars : set of char = ['A'..'Z','a'..'z'];
begin
  if not(key in validchars) then key := #0;
end;

meikl
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1347495
YOu can simple do

OnKeyPress()
begin
  if not (key in ['a'..'z', 'A'..'Z']) then key := #0;
end;

which is what meikl proposed,...
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1347496
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in ['a'..'z', 'A'..'Z', #8]) then key := #0;
end;


I would suggest including #8 so the user can backspace.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1347497
You deserve the points little man :o)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question