Link to home
Start Free TrialLog in
Avatar of edhasted
edhastedFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Delphi 5 - Date Field Validation and Trapping

I have a date input field that I want to validate that the contents REALLY are a date :-).

So the OnExit event reads:

procedure TForm1.Purchases_Postings_DateExit(Sender: TObject);
begin
     Try
        StrToDate(Form1.Purchases_Postings_Date.text);
     Except On EConvertError Do
        Begin
                ShowMessage('Please enter a valid date.');
                Exit;
        end;
     end;
end;

Where Form1.Purchases_Postings_Date.text is the input field.

However before this gets called I get the message:

Project TEST.EXE raised exception class EConvertError with message '99/99/9999' is not a valid date. Process stopped. Use stop or run to continue.

And 99/99/9999 is a suitibly suicidal bogus date.

With thanks.
ASKER CERTIFIED SOLUTION
Avatar of Parsi
Parsi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of edhasted

ASKER

The topic seems to have petered out without answering the original question about how in the code you trap a valid date.

Bringing up an error message is one way but it's not trapopoing the problem at source.

I believe this is effect unanswered which is a pity as I am sure Delphi must have a means of doing this.

If I have missed the point I would be delighted to know.

With best wishes and thanks to everyone who has contributed.

Ed
Avatar of Parsi
Parsi

Hello again edhasted

well, I am not very sure about my english, may be i cannot explain it correctly, but when you prepare your executable file and leave the Delphi environment, the error message of delphi will not appear and  only your 'Error handler module' will be executed in which you will give your suitable message and your user may understand that he has to enter the date field in the way you are waiting for.

Good luck
Parsi