Solved

Edit boxes 'n' case statements.

Posted on 1998-11-21
6
123 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now