Delphi 5 - Date Field Validation and Trapping

Posted on 2006-03-21
Last Modified: 2010-07-27
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);
     Except On EConvertError Do
                ShowMessage('Please enter a valid date.');

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.
Question by:edhasted
    LVL 2

    Accepted Solution

    Hi edhasted

    Seems that you are checking it in Delphi environment.
    If you build the .Exe and try to tun it you will see that Delphi does not generateany error
    and only displays your message. In fact while we (programmers) are programming the 'Error' is shown to let us handle
    those errors but for users who execute the .exe file only the exception happens.

    Good Luck

    Author Comment

    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.

    LVL 2

    Expert Comment

    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

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    VBA color chart bars 12 50
    wordlen challenge 3 29
    wordmultiple challenge 12 63
    Path of Workbook 3 30
    This is an explanation of a simple data model to help parse a JSON feed
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now