Board index » delphi » Validate date in TEDIT box.

Validate date in TEDIT box.

Hi,

Being a newbie to Delphi I'm trying to write a simple form to query a
database, then open a reportsmith view on the results.

I'm allowing the user to enter a "as of" date for the query, then passing a
PARAMS[0] to the query indicating the date.

What I need to do is validate the date the user enters in the TEDIT control.  
What is the easiest way to do this (and maybe even handle the exception).

Thanks

-Rob

 

Re:Validate date in TEDIT box.


Greetings Rob,

The following function will will do the trick - just pass it the contents
of the TEdit.Text property.

function isDate( const sDate : String ) : Boolean;
begin
        try
                StrToDate(sDate);
                Result := True;
        except
                Result := False;
        end;
end;

--
Mark Pritchard

Robert Jolliffe <R...@quadro.com> wrote in article
<51u9qf$...@nic.wat.hookup.net>...

Quote
> Hi,

> Being a newbie to Delphi I'm trying to write a simple form to query a
> database, then open a reportsmith view on the results.

> I'm allowing the user to enter a "as of" date for the query, then passing
a
> PARAMS[0] to the query indicating the date.

> What I need to do is validate the date the user enters in the TEDIT
control.  
> What is the easiest way to do this (and maybe even handle the exception).

Re:Validate date in TEDIT box.


Quote
R...@quadro.com (Robert Jolliffe) wrote:
>Hi,
>Being a newbie to Delphi I'm trying to write a simple form to query a
>database, then open a reportsmith view on the results.
>I'm allowing the user to enter a "as of" date for the query, then passing a
>PARAMS[0] to the query indicating the date.
>What I need to do is validate the date the user enters in the TEDIT control.  
>What is the easiest way to do this (and maybe even handle the exception).

See the function StrToDate. It raises an exception when you use
an invalid date.

Best regards,
Frank
--
// Frank Mikalsen, System Developer, Finale a.s      
// Homepage: http://home.sol.no/frankm
// Author of ShareWare: Silent Partner Backup Screensaver v2.60
// Download: http://www.winsite.com/pc/win3/desktop/spbck260.zip

Other Threads