Solved

TEdit OnKeyPress Event help

Posted on 2010-09-13
4
362 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 250 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Controlled Assessment GCSE - desperate help needed 4 112
Base1 Encode/Decode 3 86
Firemonkey webbrowser scrollbars ? 1 57
Dev express lookupcombo 3 45
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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