Board index » delphi » error trapping help needed

error trapping help needed

Sorry to bother you people with what is probably fairly simple.

I have a form that contains a few Edit boxes and one of them is used to
allow the input of a date.
It works fine and converts to a timedate without any problems.  The program
will crash though if the user was to enter an invalid date, such as
35/35/97.  Is there something that I can do to trap it easily and bring up
an error dialog box to inform the user, reset the value to a default and let
the user reenter.
I can handle the modal but am unable to stop the error crashing the system.
Also if there is an error trap, what event is the best to run it from.  (On
Change ??)
Please email me with any help.
thanks again
Tony Casbolt
t...@key.net.au

 

Re:error trapping help needed


Quote
Tony Casbolt wrote:

> Sorry to bother you people with what is probably fairly simple.

> I have a form that contains a few Edit boxes and one of them is used to
> allow the input of a date.
> It works fine and converts to a timedate without any problems.  The program
> will crash though if the user was to enter an invalid date, such as
> 35/35/97.  Is there something that I can do to trap it easily and bring up
> an error dialog box to inform the user, reset the value to a default and let
> the user reenter.
> I can handle the modal but am unable to stop the error crashing the system.
> Also if there is an error trap, what event is the best to run it from.  (On
> Change ??)
> Please email me with any help.
> thanks again
> Tony Casbolt
> t...@key.net.au

The following function should do it.

procedure ErrorChecking;
begin
   try
      strtodate(edit1.text)
   except
      showmessage('Invalid Date');
      edit1.setfocus;
   end;
end;

Wenchun

Re:error trapping help needed


Tony.

if your using DBEdits then look at the DBVldEdit Component, this object is an
alternative for the DBEdit object.
enhanced capailities are

Validating data Before leaving the field
Maintaining Focus and Caret after showing messages
Instant trapping of Required fields
Suspending validation on special events
Filling of default values on creating new records
MaskEdit capabilities
Alert beep controlable

Description:

Added is an OnValidate event to check data before leaving the field.( the OnExit
event is
executed after leaving the field). It leaves the focus on the DBVldEdit field.
Tabbing trough other fields (or controls) or clicking another object invokes the
event to
happen.
To insure that the validation can be overridden, a property CtlNames is created
which is a
list of controls that can be set that do not invoke the OnValidate event.(for
instance an Find
Button to lookup some value in a second form)

When adding a new record defaults can be filled out from the component itself.
It has a
property that can be filled out for this purpose.

The EditMask propertyis added so data can be formatted when entered. It works as
the
normal EditMask property on an MaskEdit component.

Beeping can be toggled on the validation When the message you generate beeps
also it can
get annoying for the End User.

It can be found at: Http://www.skzl.nl/~jvdvelde

Kind regards, Sjef van der Velde

Quote
Tony Casbolt wrote:
> Sorry to bother you people with what is probably fairly simple.

> I have a form that contains a few Edit boxes and one of them is used to
> allow the input of a date.
> It works fine and converts to a timedate without any problems.  The program
> will crash though if the user was to enter an invalid date, such as
> 35/35/97.  Is there something that I can do to trap it easily and bring up
> an error dialog box to inform the user, reset the value to a default and let
> the user reenter.
> I can handle the modal but am unable to stop the error crashing the system.
> Also if there is an error trap, what event is the best to run it from.  (On
> Change ??)
> Please email me with any help.
> thanks again
> Tony Casbolt
> t...@key.net.au

Other Threads