Solved

MaskEdit for Hex input?

Posted on 2002-03-19
8
2,449 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 22

Accepted Solution

by:
mnasman earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
#0 is ascii 0 which is null so do nothing.  I'm Glad you got your code working.....
0
 

Expert Comment

by:13eetle
Comment Utility
#0 is ascii 0 which is null so do nothing.  I'm Glad you got your code working.....
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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

10 Experts available now in Live!

Get 1:1 Help Now