Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MaskEdit for Hex input?

Posted on 2002-03-19
8
Medium Priority
?
2,742 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

721 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