MaskEdit for Numbers

I was looking at replacing some specialized components with a MaskEdit 
component in several forms in my application. Some changes have been 
made to MaskEdit that were way too long in coming, and I gave it a try.
What I found was that the masks are woefully inadequate for handling 
numbers. (I'd say maybe it was me, but I spent a lot of time trying to 
find something that works).
What I want: For a mixed number, I want the user to be able to tab into 
the component, type "1.25" and tab to the next field. And I want the 
component to be able to handle other numbers - not a mask that only 
works for this size number.
So what's wrong? The mask wants to indicate where characters can be 
typed, so only this field has underscores. If I allow 3 integer digits, 
the typed "1" goes into the first position, then jumps over 2 to the 
decimal where the "25" is entered (correctly). I'd like to be able to 
initialize the field with, maybe "0.00". Nothing works smoothly enough. 
If only I wanted to enter a telephone number. Am I lost here or is there 
some mask that will allow the user to enter numbers easily?
0
Patrick
2/28/2012 12:33:43 AM
πŸ“ embarcadero.delphi.ide
πŸ“ƒ 3925 articles.
⭐ 0 followers.

πŸ’¬ 10 Replies
πŸ‘οΈβ€πŸ—¨οΈ 14295 Views


Patrick Moloney wrote:
> I was looking at replacing some specialized components with a MaskEdit 
> component in several forms in my application. Some changes have been 
> made to MaskEdit that were way too long in coming, and I gave it a try.
> What I found was that the masks are woefully inadequate for handling 
> numbers. (I'd say maybe it was me, but I spent a lot of time trying to 
> find something that works).
> 
> What I want: For a mixed number, I want the user to be able to tab into 
> the component, type "1.25" and tab to the next field. And I want the 
> component to be able to handle other numbers - not a mask that only 
> works for this size number.
> 
> So what's wrong? The mask wants to indicate where characters can be 
> typed, so only this field has underscores. If I allow 3 integer digits, 
> the typed "1" goes into the first position, then jumps over 2 to the 
> decimal where the "25" is entered (correctly). I'd like to be able to 
> initialize the field with, maybe "0.00". Nothing works smoothly enough. 
> If only I wanted to enter a telephone number. Am I lost here or is there 
> some mask that will allow the user to enter numbers easily?
Take a look in help for TEditMask.
There's a list of the characters to use for different masks, the ones you might be interested in
are:
0  The 0 character requires a numeric character only in this position.  
9  The 9 character permits a numeric character in this position, but doesn't require it.  
#  The # character permits a numeric character or a plus or minus sign in this position, but
doesn't require it.
So, maybe something like  '#99999990.00;0;_' as the value for the TMaskEdit.EditMask property does
what you are after.
Cheers
Tom
-- 
Tom Brunberg
firstname.surname@welho.com
1
Tom
2/28/2012 7:04:04 AM
Or just use a normal TEdit and check the "NumbersOnly" property.  Much 
simpler than trying to use MaskEdit.

"Tom Brunberg"  wrote in message news:449004@forums.embarcadero.com...
Patrick Moloney wrote:
> I was looking at replacing some specialized components with a MaskEdit
> component in several forms in my application. Some changes have been
> made to MaskEdit that were way too long in coming, and I gave it a try.
> What I found was that the masks are woefully inadequate for handling
> numbers. (I'd say maybe it was me, but I spent a lot of time trying to
> find something that works).
>
> What I want: For a mixed number, I want the user to be able to tab into
> the component, type "1.25" and tab to the next field. And I want the
> component to be able to handle other numbers - not a mask that only
> works for this size number.
>
> So what's wrong? The mask wants to indicate where characters can be
> typed, so only this field has underscores. If I allow 3 integer digits,
> the typed "1" goes into the first position, then jumps over 2 to the
> decimal where the "25" is entered (correctly). I'd like to be able to
> initialize the field with, maybe "0.00". Nothing works smoothly enough.
> If only I wanted to enter a telephone number. Am I lost here or is there
> some mask that will allow the user to enter numbers easily?
Take a look in help for TEditMask.
There's a list of the characters to use for different masks, the ones you 
might be interested in
are:
0  The 0 character requires a numeric character only in this position.
9  The 9 character permits a numeric character in this position, but doesn't 
require it.
#  The # character permits a numeric character or a plus or minus sign in 
this position, but
doesn't require it.
So, maybe something like  '#99999990.00;0;_' as the value for the 
TMaskEdit.EditMask property does
what you are after.
Cheers
Tom
-- 
Tom Brunberg
firstname.surname@welho.com
0
John
2/28/2012 12:46:43 PM
On 2/28/2012 7:46 AM, John Friel III wrote:
> Or just use a normal TEdit and check the "NumbersOnly" property.  Much
> simpler than trying to use MaskEdit.
>
It is simpler.
-1
Patrick
2/28/2012 12:59:06 PM
On 2/28/2012 2:04 AM, Tom Brunberg wrote:
>
> Take a look in help for TEditMask.
> There's a list of the characters to use for different masks, the ones you might be interested in
> are:
> 0  The 0 character requires a numeric character only in this position.
> 9  The 9 character permits a numeric character in this position, but doesn't require it.
> #  The # character permits a numeric character or a plus or minus sign in this position, but
> doesn't require it.
>
> So, maybe something like  '#99999990.00;0;_' as the value for the TMaskEdit.EditMask property does
> what you are after.
>
> Cheers
> Tom
>
I tried everything I could think of with that EditMask yesterday. The 
user gets "1", then six spaces, then ".25".  Doesn't look anything like 
a number. Asking the user to move character by character with the arrow 
key is just unacceptable.
I think they beefed up the documentation on this since the original 
release of IB. I even put in a QC entry that MaskEdit was poorly 
documented. So its here, but the writer added no insight into how it 
works, and the description is minimal. In fairness there, if the 
developer provided better documentation of what he had created, maybe he 
would have seen the difficulty in working with numbers. (Or maybe that 
wasn't even what he wanted.)
0
Patrick
2/28/2012 1:08:39 PM
"John Friel III" <john@frieltek.com> wrote in message 
news:449065@forums.embarcadero.com...
> Or just use a normal TEdit and check the "NumbersOnly" property.  Much
> simpler than trying to use MaskEdit.

Unfortunately that only works for integer fields - doesn't allow decimal.
For decimal values one can also use OnKeyPress. I normally create one of 
these per form and assign all appropriate controls to use that.
  if not (Key in [#1..#31, "0".."9", '.']) then
    Key := #0;
-- 
Wayne Niddery (TeamB)
"'Thank you, Occupy Wall Street. With your vivid example of anticapitalist 
squalor, I've been able to convince all three of my children to become 
investment bankers"  - P. J. O’Rourke
0
Wayne
2/28/2012 1:12:54 PM
On 2/28/2012 8:12 AM, Wayne Niddery wrote:
> "John Friel III"<john@frieltek.com>  wrote in message
> news:449065@forums.embarcadero.com...
>> Or just use a normal TEdit and check the "NumbersOnly" property.  Much
>> simpler than trying to use MaskEdit.
>
>
> Unfortunately that only works for integer fields - doesn't allow decimal.
>
> For decimal values one can also use OnKeyPress. I normally create one of
> these per form and assign all appropriate controls to use that.
>
>    if not (Key in [#1..#31, "0".."9", '.']) then
>      Key := #0;
>
Oh yeah, there was that problem too. I tried that.
I was considering, rather than OnKeyPress, to just check the value when 
the user submits the form. Workable.
I was also trying to get some standard method to display data that is 
retrieved. Some data is not just dollars and cents, but various levels 
of decimals and/or integers. Simply tweaking a mask on a form would be 
nice, but I don't think Delphi can do that.
I'm using PBEditPack for number entry, which works pretty well. But it's 
just one more separate piece I would replace with standard components if 
I could. It looks like it's still giving me something I can't get standard.
0
Patrick
2/28/2012 1:38:20 PM
Patrick Moloney wrote:
> I tried everything I could think of with that EditMask yesterday. The 
> user gets "1", then six spaces, then ".25".  Doesn't look anything
> like a number. Asking the user to move character by character with
> the arrow key is just unacceptable.
The control is simply not suitable and also not intended for the
purpose you are trying to use it for. It was designed for things like
phone numbers or area codes, where you have a fixed number of digits.

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://codenewsfast.com
http://groups.google.com
0
Peter
2/28/2012 8:20:55 PM
Patrick Moloney wrote:
> On 2/28/2012 2:04 AM, Tom Brunberg wrote:
> > 
> > Take a look in help for TEditMask.
> > There's a list of the characters to use for different masks, the ones you might be interested in
> > are:
> > 0  The 0 character requires a numeric character only in this position.
> > 9  The 9 character permits a numeric character in this position, but doesn't require it.
> > #  The # character permits a numeric character or a plus or minus sign in this position, but
> > doesn't require it.
> > 
> > So, maybe something like  '#99999990.00;0;_' as the value for the TMaskEdit.EditMask property
> > does what you are after.
> > 
> > Cheers
> > Tom
> > 
> 
> I tried everything I could think of with that EditMask yesterday. The 
> user gets "1", then six spaces, then ".25".  Doesn't look anything like 
> a number. Asking the user to move character by character with the arrow 
> key is just unacceptable.
> 
> I think they beefed up the documentation on this since the original 
> release of IB. I even put in a QC entry that MaskEdit was poorly 
> documented. So its here, but the writer added no insight into how it 
> works, and the description is minimal. In fairness there, if the 
> developer provided better documentation of what he had created, maybe he 
> would have seen the difficulty in working with numbers. (Or maybe that 
> wasn't even what he wanted.)
Ok, then I would suggest to use a TEdit and validate the entry in the OnExit event. If wrong, use
SetFocus to set the focus back to the Edit control.
Cheers
Tom
-- 
Tom Brunberg
firstname.surname@welho.com
0
Tom
2/28/2012 8:50:05 PM
That is the conclusion I came to. After failing to find a solution in testing I posted here in case I was missing something.
Thanks.
0
Patrick
2/29/2012 2:05:30 PM
Well it is either TEdit or the 3rd Party component I currently use. 
This search was triggered by one form that had a TEdit and looked bad compared to the usual 3rd Party component. I was going to "Fix" it, but decided to take a fresh look at whether the 3rd party component is still necessary. It would be nice to remove the complexity and risk of outside components thruout the application. And, right alignment has been improved in the MaskEdit. But the mask is not what I need. So, I think it's back to the 3rd party component, which displays nicely.
I am curious if the mask that is used on a Field works better. I have some of them set on ClientDataSets used with DBGrids and they look better. But I don't edit there.
0
Patrick
2/29/2012 2:16:10 PM
Reply: