Board index » delphi » Masks, DBEdit, dates and NULL values

Masks, DBEdit, dates and NULL values

Hello.

We are trying to use masks with DBEdit components linked to date fields.
We would like the user to be able to enter dates without having to enter
the separators.

If we save the mask with the data (put a 1 as the second field of the
mask), the user cannot enter an empty date (NULL) because the default
validation refuses '    /  /  '.

If we do not save the mask with the data (put a 0 as the second field
of the mask), the tdatefield validation refuses the dates (because, of
course, the separatore are not there).

The solutions we see are:
1. avoid masks altogether (not user-friendly)
2. write a DBEdit descendant which would have sensible validation
routines to use with masks (lots of work)
3. bypass the default TDateField validation routines (not very
practical)

I cannot believe that we are the first to experience this problem.

Anybody out there solved it?  Did we miss something?

Thanks.

Bye.
--
Robert Gagnon | "Marketing:  The Art of Using the Truth to fool the  
              | consumers."
LONAS Informatique, 3395 Picard, St-Hyacinthe (QC) J2S 1H3 Fax:
(514)774-5160
lo...@maska.net   |   Opinions expressed are my own   |    Tel:
(514)778-2288

 

Re:Masks, DBEdit, dates and NULL values


Quote
Robert Gagnon <lo...@maska.net> wrote:
>Hello.

>We are trying to use masks with DBEdit components linked to date fields.
>We would like the user to be able to enter dates without having to enter
>the separators.

>If we save the mask with the data (put a 1 as the second field of the
>mask), the user cannot enter an empty date (NULL) because the default
>validation refuses '    /  /  '.

<snip>

Quote
>I cannot believe that we are the first to experience this problem.

>Anybody out there solved it?  Did we miss something?

>Thanks.

>Bye.
>--

Hi,
We ran into a similar problem here.  We resolved it by saving the mask with the value and putting the following
code in an Application Exception event.

  if E is a whole lot of other exceptions
   else if E is EConvertError then
   begin
      DateTxt := '__/__/____';
      if (ActiveControl is TDBEdit) then
      begin
         if (ActiveControl as TDBEdit) = dbeJoinDt then
         begin
            if dbeJoinDt.EditText <> DateTxt then
            begin
               Application.ShowException (E);
            end
            else
               TPeopleJointDt.AsString := '';
         end

The only problem I've found with this is if you are editing a record with a value in the date field, press Delete, the
value disappears, but now you have to press Tab twice to get to the next field.  If you find any other solutions, please
let me know!

HTH,
Mark Reaux
Diamond Data Systems, Inc.

Other Threads