How trap TDataset date-exception?

Hi!

I have a TDBEdit connected to a DateTime field in a dataset. Now, if I type "10" into the TDBEdit, that means that I am referring to the 10th day in the current month and current year. So I want "10" to be converted into "2000-01-10", which is a valid date.

But before I get a chance to convert the contents I get an exception saying "'10' is not a valid date and time!".

The ideal thing would be to do the conversion in the onExit event of the TDBEdit, but the exception above is raised before I get there!

I've solved it before by putting an ordinary TEdit control on top of the TDBEdit and switch between them, but I really would like a simpler way!

Help!!
DippenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kretzschmarCommented:
hi dippen,

i guess(not tested),
you can use the onsettext-event of the underlying Tfield
or
you can also use the onvalidate-event of the underlying Tfield
where you can place the code, which you used with the tedit.

remark:
this events are also available by none-persistant fields

meikl
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PeterLarsenCommented:
Maybe you can override the Mask property. Property TCustomMaskEdit.EditMask is protected so its possible make it visible in a new component.
0
DippenAuthor Commented:
I haven't tested it yet, but it's obviously correct! Thanks alot, I wasn't aware of the fact that these events existed!

Regards, Daniel
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.