Board index » delphi » How to handle dates in a DBEdit

How to handle dates in a DBEdit

Please help me out here.

What is the appropriate way to handle dates in a DBEdit so that:
  - empty dates are allowed
  - valid dates only are allowed
  - the text turns red if not valid

tnx

marcel van eijkel
v952...@si.hhs.nl
eij...@hetnet.nl
IT-Student
Holland

 

Re:How to handle dates in a DBEdit


Databases don't like empty date fields. But that doesn't mean you can't
do it. You have to be aware that date fields are tricky and handle them
carefully so they don't bring your program to a screeching halt. The
following code will let you access date fields without getting
errors:
var
        s:string[255]; //make sure string is big enough
begin
        if TABLE1MYDATE.getdata(@s) then
                write(f,TABLE1MYDATE.value)
        else
                you have a bad datefield;

See the setdata method described in the help files for putting bad data
into a date field.

Use editmask or even a TMaskEdit box to get valid dates. The help file
has a lot on this. TMaskEdit even has a preview thing that lets you see
how your mask will work at run time.
Actually, I am very dissatisfied with how TMaskEdit and editmasks work. I
would prefer the numbers were entered from right to left instead of left
to right.  So I will probably write my own mask edit stuff one of these
days.

As for turning red, I leave that up to you. <g>

Hope that helps a little.

In article <01bcfa8f$1f47d580$051479c3@marcel-s>, v952...@si.hhs.nl
says...

Quote
> Please help me out here.

> What is the appropriate way to handle dates in a DBEdit so that:
>   - empty dates are allowed
>   - valid dates only are allowed
>   - the text turns red if not valid

> tnx

> marcel van eijkel
> v952...@si.hhs.nl
> eij...@hetnet.nl
> IT-Student
> Holland

Other Threads