Board index » delphi » Edit masks for DBEdit

Edit masks for DBEdit

Hi,

does anyone know what's the easiest way to add an editmask to a DBEdit
in Delphi 1.0?  Does this involve making a new component?

Thanks for any advice,

Dan

 

Re:Edit masks for DBEdit


Quote
Dan Axtell <daxt...@connix.com> wrote:
> Hi,

> does anyone know what's the easiest way to add an editmask to a DBEdit
> in Delphi 1.0?  Does this involve making a new component?

EditMask is a property of the TField linked to your DBEdit.
Double-click on your TTable or TQuery, add the fields you want and
then select it in the Object Inspector to access its properties.

Good luck!

Jasper

PS: please take into consideration
- when replying, I just think I know;
- when asking, be sure that I don't.

Re:Edit masks for DBEdit


you can assign an edit mask to the TField component associated with the
DBEdit.  Use the Object Inspector to examine the TField in question and find
the 'EditMask' property.

In article <31EA698D.2...@connix.com>

Quote
Dan Axtell <daxt...@connix.com> wrote:
> Hi,

> does anyone know what's the easiest way to add an editmask to a DBEdit
> in Delphi 1.0?  Does this involve making a new component?

Re:Edit masks for DBEdit


In article <4sh922$...@news.cc.utah.edu>,
   lawre...@biology.utah.edu (Jeffrey Lawrence) wrote:

Quote
>you can assign an edit mask to the TField component associated with the
>DBEdit.  Use the Object Inspector to examine the TField in question and
find
>the 'EditMask' property.

>In article <31EA698D.2...@connix.com>
>Dan Axtell <daxt...@connix.com> wrote:
>> Hi,

>> does anyone know what's the easiest way to add an editmask to a DBEdit
>> in Delphi 1.0?  Does this involve making a new component?

Actually, I've generally found edit masks to be fairly useless. But the
GetText/SetText events of TField components are extremely useful. You can
translate the underlying data to/from any presentation and edit format.
There is one missing piece though -- you might need to create your own
TDBEdit component which suppresses the TDBEdit's call to the TField's key
validation routine -- this lets your own component decide what keys are
valid. (If someone can suggest a way to avoid calling an inherited method,
but to still call the grandparent method, then this could be achieved by
inheriting from TDBEdit).

We use this for doing things like presenting percentages in decimal format
with a % sign, while maintaining the underlying data in fractional form. It
works especially well if you want to allow the user to enter data
in several different ways, which you will decode as it happens.

 I find edit masks extremely poorly suited to most realistic data-entry
scenarios. For example, a US-style zip code mask fails for Canadian postal
codes, and the mask won't support both. North American phone numbers can be
force-fit, but then not overseas numbers. Etc. Also, they are ugly (IMHO).

--
Brad Aisa <ba...@tor.hookup.net>  http://www.hookup.net/~baisa/

"The highest responsibility of philosophers is to serve as the
guardians and integrators of human knowledge."   -- Ayn Rand

Re:Edit masks for DBEdit


Hi There,

With regard to the general discusiion on EditMasks, I've got a form with
a number of data fields on it. Wanting to be smart I assigned a date
edit mask to each field and set the save mask with data flag.

What happens now is that if the user tabs across a date field, on entry
the mask is displayed and on exit Delphi attempts to write the empty
mask to the underlying datafield resulting in a database error since it
is not a valid date.

Working around this is a real pig. Any comments?
--
Sol Barron

Re:Edit masks for DBEdit


Ideas, cheapest to most expensive -

1. Get rid of the dbedit and put a standard tedit in its place. Trap
OnKeyPress to allow only entry of digits and slashes. In the OnExit
event call a routine which does a strtodate on the text in the tedit and  
trap the exception if invalid and put up a messagedlg to alert the user.
Finally in the BeforePost event of your dataset do a
tableField.asdatetime:=strtodate(tedit.text). Long winded but it works a
treat.

2. Get a data-aware calendar-dbedit and prevent the user typing in the
exit part, forcing him to get the date from the calendar.

3. Get InfoPower 2.0 which has a dbedit which has properly working
masks.

Nick Spurrier (MoDESoft, UK)

Re:Edit masks for DBEdit


In article <EQRy7CAcG89xE...@barron.demon.co.uk>,
   Sol Barron <s...@barron.demon.co.uk> wrote:

Quote
>Hi There,

>With regard to the general discusiion on EditMasks, I've got a form with
>a number of data fields on it. Wanting to be smart I assigned a date
>edit mask to each field and set the save mask with data flag.

>What happens now is that if the user tabs across a date field, on entry
>the mask is displayed and on exit Delphi attempts to write the empty
>mask to the underlying datafield resulting in a database error since it
>is not a valid date.

>Working around this is a real pig. Any comments?

Yes. Use the GetText and SetText events to translate back and forth between
underlying field representation and edit box text representation.

If Delphi came with documentation, this would have been clearly explained.

--
Brad Aisa <ba...@tor.hookup.net>  http://www.hookup.net/~baisa/

"The highest responsibility of philosophers is to serve as the
guardians and integrators of human knowledge."   -- Ayn Rand

Re:Edit masks for DBEdit


Quote
ba...@tor.hookup.net (Brad Aisa) wrote:

<<---------------<<snip>>--------------->>

Quote

>>What happens now is that if the user tabs across a date field, on entry
>>the mask is displayed and on exit Delphi attempts to write the empty
>>mask to the underlying datafield resulting in a database error since it
>>is not a valid date.

>>Working around this is a real pig. Any comments?
>Yes. Use the GetText and SetText events to translate back and forth between
>underlying field representation and edit box text representation.
>If Delphi came with documentation, this would have been clearly explained.
>--
>Brad Aisa <ba...@tor.hookup.net>  http://www.hookup.net/~baisa/

Could someone please post some demo code on just how to use the GetText and
SetText events please?

TIA
keith

Other Threads