Solved

MaskEdit for Hex input?

Posted on 2002-03-19
8
2,516 Views
Last Modified: 2012-05-04
I'd like to use the Maskedit component to allow a user to enter a Hex number in the form 0xABCD

I've figured out the edit mask so far to be ">\0xaaaa<", but this allows ALL letters.  How can I specify letters from A-F only?
0
Comment
Question by:PaulKorzycki
  • 4
  • 2
  • 2
8 Comments
 

Expert Comment

by:13eetle
ID: 6880085
write a routine in the OnKeyCapture event of the mask edit.  Make sure that the key pressed fits within the ascii range that you are interested in.

like

  if ((Key >= 48) and (Key <= 57)) or ((Key >= 65) and (Key <= 72)) then .....

  where 48 to 57 is ascii 0 to 9 and 65 to 72 is A to H.

Hope that helps.
0
 

Author Comment

by:PaulKorzycki
ID: 6880129
Actually the maskedit that I'm using is a component that comes with a stringgrid, so it doesn't have the on OnKeyPress event, but it does use the same mask properties as the Maskedit component.  Even still, how would I go about using this to filter the input?  

if (key is within specified limits) then
  <do nothing>
else
  <delete the last character from the input field???>

This raises many cases, such as if the string is blank, or the user types the character in the middle of the string.  Can you specify somehow for the newly pressed character NOT to be accepted?

Isn't there a slick way to create a mask to allow this?
0
 

Expert Comment

by:13eetle
ID: 6880205
I just did this...

 if ((Key >= 48) and (Key <= 57)) or ((Key >= 65) and (Key <= 70)) then
   MaskEdit1.Text := MaskEdit1.Text + IntToSTr(ord(key));

I used this on the OnKeyDown event of the Maskedit (I said OnKeyCaputre earlier, I was wrong....).  I tried it out and it seems to work fine.  Will this do the trick???  I don't know of any way to get the mask to range check to that degree but there still could be a way....
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6880904
Hello

  use this code in the OnKeyPress of the Edit or maskedit

  if not (Key in ['0'..'9','a'..'f','A'..'F',#8]) then
    Key := #0;

the #8 to allow the user to use the backspace

Best regards
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 100 total points
ID: 6880920
Hello

  use this code in the OnKeyPress of the Edit or maskedit

  if not (Key in ['0'..'9','a'..'f','A'..'F',#8]) then
    Key := #0;

the #8 to allow the user to use the backspace

Best regards
0
 

Author Comment

by:PaulKorzycki
ID: 6880953
I had to modify the component that I'm using (it had overriden the OnKeyPress event), but I added your code and it works!

So if Key is set to #0, then the keypress is not accepted?
0
 

Expert Comment

by:13eetle
ID: 6880979
#0 is ascii 0 which is null so do nothing.  I'm Glad you got your code working.....
0
 

Expert Comment

by:13eetle
ID: 6880983
#0 is ascii 0 which is null so do nothing.  I'm Glad you got your code working.....
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 72
Find and Replace Stream with 0s 8 61
Base1 Encode/Decode 3 77
How to remove Recent Projects from Embarcadero C++ builder XE10. Berlin 2 54
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

11 Experts available now in Live!

Get 1:1 Help Now