• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

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!!
0
Dippen
Asked:
Dippen
1 Solution
 
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
 
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

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now