?
Solved

TEdit OnKeyPress Event help

Posted on 2010-09-13
4
Medium Priority
?
369 Views
Last Modified: 2012-05-10
I have a function that converts a number to roman and visa versa. (thanks to EE expert).

I need to prevent users from entering anything other than the following characters

0..9, or  I,V,X,L,C,D,M

into a TEdit control

I guess i need to allow a backspace, but nothing else. (example, no spaces, periods, etc. etc)

thanks
0
Comment
Question by:Looking_4_Answers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:Looking_4_Answers
ID: 33666498
sorry, i meant to rephrase it

if not (Key in [#8, '0'..'9', 'I','V','X','L','C','D','M']) then
  Key := #0;

i need to prevent the person from entering a numeric if they are already entering a roman numeral character, and visa versa (if the enter a 'I','V','X','L','C','D','M'  then they can't enter a 0..9
0
 
LVL 25

Accepted Solution

by:
epasquier earned 1000 total points
ID: 33666932
Voila !
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
Var
 Txt:String;
 i64:Int64;
 SetAllowed:Set of Char;
Const
 AllowDigits=['0'..'9'];
 AllowRomans=['I','V','X','L','C','D','M'];
begin
 Txt:=(Sender As TEdit).Text;
 if Txt='' Then SetAllowed:=AllowDigits+AllowRomans Else
  if TryStrToInt64(Txt,i64)
   Then SetAllowed:=AllowDigits
   Else SetAllowed:=AllowRomans;
 SetAllowed:=SetAllowed+[#8];
 Key:=UpCase(Key); // convert i, v, x... to I, V, X
 If Not (Key In SetAllowed) Then Key:=#0;
end;

Open in new window

0
 
LVL 9

Expert Comment

by:Mahdi78
ID: 33667012
Great !
Très bonne idée.
0
 

Author Closing Comment

by:Looking_4_Answers
ID: 33674904
NICE JOB!  Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

741 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