Board index » delphi » Restricting input of numbers

Restricting input of numbers

I'm not sure whether this message falls under this newsgroup. Sorry if it
doesn't.

Here's my query.

I need to restrict the input of numerical data in Edit. Be it TEdit /
DBEdit.

Well, I'm aware this can be achieved by using TMaskEdit. But MaskEdit cannot
be
used for data-aware controls.
I'm also aware that if I use data-aware controls then it can be restricted
by using the
persistent fields Edit & Display Formats. Drawback of this technique is, the
user is
shown 12345.45 where as the internal value is 12345.444444445.
(The fields datatype being float.)
Now if I add two such values or multiply them then the difference between
expected
result and calculated result is +/- 0.1 approx (after rounding)

What must be done for this discrepancy. Should I change the datatype to
numeric or
what ??? I'm confused.

Hope U get my query.
TIA.

Jatin N. Bhoir
jati...@hotmail.com

 

Re:Restricting input of numbers


It depends on how you want to restrict the intput. First, you will have to
use different techniques for TEdit and TDBEdit. If you want to restrict the
range of the value set the Max and Min properties of the TField object. For
TEdit you will probably have to use the OnChange event.

The solution to the floating point problem depends on what database you are
using. One approach is to assign the value to a Currency type variable
before doing any math. The Currency type is a scaled integer so it
eliminates floating point imprecision. However, Currency is fixed at four
digits to the right of the decimal.

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to questions received via email)

Re:Restricting input of numbers


Quote
Bill Todd wrote in message <7sh7l2$gu...@forums.borland.com>...
>It depends on how you want to restrict the intput. First, you will have to
>use different techniques for TEdit and TDBEdit. If you want to restrict the
>range of the value set the Max and Min properties of the TField object. For
>TEdit you will probably have to use the OnChange event.

Bill, I don't intend to restrict the values of data by min and max.
What my aim is something what we did in Clipper or xBased languages
'SET DECIMAL TO n '. where n is the number of decimals you expect from user.

Thanx,
Jatin N. Bhoir
jati...@hotmail.com

Re:Restricting input of numbers


You can use the EditMask property of the field object for database input and
the TMaskEdit component for non-database input.

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to questions received via email)

Other Threads