Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MaskEdit for Hex input?

Posted on 2002-03-19
8
Medium Priority
?
2,810 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
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.

 
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 400 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

Technology Partners: 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

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Loops Section Overview
Suggested Courses

916 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