Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick Need: Validate one Field against another BeforeEdit

Status
Not open for further replies.

BrianDHuff

Programmer
Jun 23, 2003
11
US
I have a Tdataset named 'jobs'(ADO Connecting to Access) with the following fields:

jobs.end_date (TDateTime)
jobs.ship_date (TDateTime)

I need a good way to validate that jobs.end_date is not greater than jobs.ship_date BEFORE posting the changes.

I of course can check it in the beforeedit method, however, this seems to stop Delphi from posting all changes, regardless if the date is valid or not.

Looking for direction here, thanks!
 
I think you want to use the BeforePost event. BeforeEdit fires when you change the dataset's state to Edit. BeforePost fires just prior to posting the data. So, your code would look something like this:
Code:
If jobsEnd_date.AsDateTime > jobsShip_Date.AsDateTime then
begin
  ShowMessage('End Date cannot be greater than Ship Date');
  sysutils.Abort;
end;

-D
 
Yeah, that would be the first thought, went down that road, the additional issue (which I did fail to mention) is that I have a TPlanner (From TMSSoftware) that is doing the update here, if I do a beforepost or beforeedit here, then it clears out the entire TPlanner item... I think that really is where my problem is. I can check and validate the fields, was just looking for a better way I suppose... ugh, oh well, have to start stepping through everything now.

Thanks again for the suggestion, my initial request should have included the extra information.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top