Solved

TEdit OnKeyPress Event help

Posted on 2010-09-13
4
353 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
  • 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

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 253
PDF library for Delphi 2 89
How to use Hashing sha1 in Delphi 2010 4 163
code issue 8 85
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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

13 Experts available now in Live!

Get 1:1 Help Now