* * *

Author Topic: Check on date with TDBDateEdit  (Read 470 times)

mangakissa

  • Hero Member
  • *****
  • Posts: 703
Check on date with TDBDateEdit
« on: March 03, 2017, 02:39:03 pm »
I use TDBDateEdit to fill the birthday of a person. If I type in '33-3-2012' the object checks if the date is valid. If doesn't the fieldvalue is set to NULL (30-12-1899). There's no warning of invalid date. That's very nice. the application doesn't reproduce an error dialog with the option to kill the program. 
I know the field is NULL, because event onEditingDone gives the zero date (also when checking the date before saving the actual record)
Code: Pascal  [Select]
  1. showmessage(datetostr(birthday.date))
So how do I tell the user that the filled in dat is invalid. Now the record is saved without a date.
Lazarus 1.64 (32b) / FPC 3.0
Windows 10

rvk

  • Hero Member
  • *****
  • Posts: 2603
Re: Check on date with TDBDateEdit
« Reply #1 on: March 03, 2017, 03:02:28 pm »
I know the field is NULL, because event onEditingDone gives the zero date (also when checking the date before saving the actual record)
The OnEditingDone doesn't "give" anything. It's just an event.

What value do you check in OnEditingDone?

I'm not sure how it's in TDBDateEdit, but in TDateEdit the TDateEdit.Text has the invalid value just before validating is done. TDateEdit.Date isn't filled yet and can only be filled after validation. So checking TDateEdit.Text yourself in OnEditingDone should work.

Quote
OnEditDone: Event handler when editing is done. The user definitely has finished editing, the resulting text e.g. can be validated.

mangakissa

  • Hero Member
  • *****
  • Posts: 703
Re: Check on date with TDBDateEdit
« Reply #2 on: March 03, 2017, 04:09:49 pm »
You're absolutely right. Sometimes I forget there are other properties to check.
Lazarus 1.64 (32b) / FPC 3.0
Windows 10

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus