Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Edit boxes 'n' case statements.

Posted on 1998-11-21
6
Medium Priority
?
137 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
viktornet earned 100 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Loops Section Overview
Suggested Courses

971 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