[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

TEdit OnKeyPress Event help

Posted on 2010-09-13
4
Medium Priority
?
378 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 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