i downloaded a DBDateTimePicker which i am using to edit dates in a table, a start date and completion date. When appending to a table in normal edit boxes i use the following code before the append and post in order to prevent a completion date being set before a start date.
if (DTPAddStartDate.Date) > (DTPAddCompletionDate.Date) then
begin
raise Exception.Create ('The Completion date of a Job can not be before a Start Date');
abort;
end;
The problem is that i want to be able to achieve the same thing when editing dates via the DBDateTimePickers, if i have similar code on the BeforePost event or something then i will get premature error messages as the user may not have had a chance to edit the other related DBDateTimePicker. I have no idea how i could relate the two fields so that i can validate them together somehow or come up with another solution to the problem, any suggestions?
(Im using an adotable connected to access and the component was downloaded from the following link, http://apollosoft.net/jms/).
I guess you are using the
TDBDateTimePickerfromthis pagebut hard to say, it’s missing in your question at this time.However you may use the field’s
OnValidateevent which is being fired whenever the value is changed, but it’s the stage when the data are going to be written do the database, so it’s IMHO the unnecessary wasting of time.You can validate the values before they tries to update the record, what is in the case of (almost ?)
every DB aware control when you try to exit the control, so you may pretty easily add some validation event, something like
OnCanUpdateto your date time picker.Because of missing link to the source where did you get your component I’ll assume you are using this
TDBDateTimePicker. If you add to theDBDateTimePicker.pasfile the following lines and rebuild your package where is installed, the newOnCanUpdateevent will appear in the component’s Object Inspector. This event if you use it has one important parameterAllowed, if you set it to True you will allow the component to update the record, if you set it to False (what is default) no data will be updated in your dataset. So it’s the place where you can do the validation and decide you want to update record or not.So the code in the
OnCanUpdateevent may looks like this (note you can use this event as common for both of your date time pickers).