TDateEdit 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 76022.1630@compuserve.com Description =========== TDateEdit is a standard Delphi 2 TEdit control, with two new boolean methods: IsValidDate and IsValidNumber. 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.} ; 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. Numeric Validation ================== Checking the DateEdit1 for a valid number is done the same way. It will check for a valid Pascal-style number (positive or negative integer or float only, scientific notation is not checked at this time) so the contents may be safely converted with StrToFloat. What I mean by Pascal style number is this: If a decimal point is encountered, it must have a valid digit on either side of it. For example, -1.0 or 0.99 is a valid Pascal-style number, but .9 is not. Some languages let you get away with this, but not Pascal, so the method will return false if the DateEdit control contains something like (.9) or (1.) I suggest converting the contents to a float, then using Round or Trunc as desired to convert the value to an integer. I spent more time being concerned with making this component check dates properly than checking all possible number formats... so it can use some improvement in this area. But for simple numbers it works fine. Errors ====== The component will return a short error message if the date (or the number) is invalid, but it *does not* generate an exception. Feel free to remove these messages from the code if they're annoying, or substitute with some other message. 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. 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, 76022.1630@compuserve.com http://members.aol.com/robertm782/public/sbcapage.htm