Solved

MaskEdit for Hex input?

Posted on 2002-03-19
8
2,621 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
[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
  • 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
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!

 
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

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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