Board index » delphi » Validating the value stored in a dbf date field

Validating the value stored in a dbf date field

Hello, what is the best way to validate the contents of a date field to see
if the value stored is a valid value for a date?

Thanks
Will

 

Re:Validating the value stored in a dbf date field


Every field have the OnValidate evenmt - check a value there

--
With best regards, Mike Shkolnik
E-mail: mshkol...@scalabium.com
WEB: http://www.scalabium.com

Quote
"Will" <NoS...@SoftTech.com> wrote in message

news:3fd94c42@newsgroups.borland.com...
Quote
> Hello, what is the best way to validate the contents of a date field to
see
> if the value stored is a valid value for a date?

> Thanks
> Will

Re:Validating the value stored in a dbf date field


Quote
Will wrote:
> Hello, what is the best way to validate the contents of a date field to see
> if the value stored is a valid value for a date?

Do you mean *before* posting to the database? If so, use the BeforePost
event, something like this:

var
   TestDate : TDateTime;
begin
   try
     TestDate := StrToDate(your_field_value);
   except
     on EConvertError do begin
       ShowMessage(TestDate + ' is not a valid date');
       SysUtils.Abort;
     end;
   end;
end;

--
jc

Remove the -not from email

Re:Validating the value stored in a dbf date field


Quote
Jeremy Collins wrote:
> ShowMessage(TestDate + ' is not a valid date');

               ^^^^^^^^
That's not correct obviously, but hopefully you get the
idea ;-)

--
jc

Remove the -not from email

Other Threads