=============================================================
TDateEdit
Version 2, January 1999
Delphi TEdit control with date and simple numeric validation.

This component is Freeware! Complete with source code.
It was written in Delphi 2, but you can recompile it for
whatever version you have, since the source is included.

Brought to you by:
Robert Manning
South Bay Computer Assistance
PO Box 21, Stanton, CA 90680
RobertM782@aol.com
http://members.aol.com/robertm782/public/sbcapage.htm
http://members.aol.com/rjmsite2/public/prog1.html
=============================================================

Description
===========
TDateEdit is a standard Delphi 2 TEdit control, with two new
boolean methods: IsValidDate and IsValidNumber. There are also
four new fields for defining error messages. TDateEdit will
only return true for four-digit years, so it is Y2K compliant.
It actually only considers years between 1900 and 9999 to be
valid (you can change the lower limit if you like, I recommend
not using less than 1000).

Example
=======
Both methods return boolean true or false, to make writing it into
an expression very simple. For example, to check whether the
contents of the edit control is a valid date, you'd code:

if DateEdit1.IsValidDate then
begin
 {contents of DateEdit1 is a valid date, and you can safely use
  StrToDate on it, such as:}
  SomeTDateTimeField.AsDateTime := StrToDate(DateEdit1.Text);
end
else
 {contents of DateEdit1 is not a valid date, give user an
 error message if desired. the component will generate an error
 message for you, but does not generate an exception.}
 ;

The IsValidNumber function is used in a similar manner. Please
read the enclosed file UNIT1.PAS for a short usage demo.

Error Messages
==============
This version of TDateEdit has four definable error messages, for
use when the IsValidDate function finds an error during parsing.
MonthErrorMsg, DayErrorMsg, YearErrorMsg, and UnknownFormatErrMsg
are all properties you can set in the object inspector. A default
message is entered in each, change it to whatever you like.

How it works
============
The component will use your current settings in your Windows
environment for checking the date format. So, it is ok if you
are using M/D/Y, D/M/Y, or Y/M/D date formats (as set in the
ShortDateFormat global variable). The component will also use
the current DateSeparator character as defined in your Windows
environment. It will also properly check for February 29th in
leap years. This has been tested in Windows 95, if you want to
use it in any other version or OS, you'll have to alter the
code yourself.

Numeric Validation
==================
Checking the DateEdit for a valid number is simply done using
the standard Pascal procedure Val. The previous version of this
component parsed the edit field, and did not check for all possible
valid number types. So, I decided to go the easy route this time
and not reinvent the wheel.

During the CheckDateFormat function, the CheckNumberFormat function
is called, which also does numeric validation. But, since we're
only interested in positive integers, it handles things a bit
differently than the TextNumberFormat function.

Errors
======
The component will return an error message if the date is invalid,
or no error message if you delete the default messages. Tt *does not*
generate an exception. The IsValidNumber does use the Val procedure
inside a try-except block, but no runtime error should be generated
to stop execution, as the exception simply sets the function return
value to false.

Installation
============
Install the component in the usual way, it is set up to register
itself on the Samples component palette tab.

Author's Note
=============
Please let me know if you have any trouble using this component. As
usual, with a free component, no guarantee or warranty is expressed or
implied, blah blah blah ;-) But please let me know if something goes
wrong, or if you have suggestions.

You also have my permission to use this component in any way you
want, including recoding it. All I ask is that if you do happen to
improve the coding, I would appreciate a copy of the new unit ;-)

Enjoy!

Robert Manning
South Bay Computer Assistance
PO Box 21, Stanton CA 90680 USA
RobertM782@aol.com
http://members.aol.com/robertm782/public/sbcapage.htm
http://members.aol.com/rjmsite2/public/prog1.html
