Daniel Marschall
Daniel Marschall

Reputation: 3879

Combining OnValidate and OnBeforePost?

As example, I have a form with a DBNavigator and a few DBEdits.

enter image description here

I want to achive the following:

  1. When the user enters something wrong in the DBEdit and wants to switch to another control, a warning should be displayed, but he can continue working.
  2. When the user wants to post the dataset, the post will be rejected, and the warning will be displayed again.

The problem is, that OnValidate is just a TFieldNotifyEvent and therefore cannot tell the application if the edit was valid, so there is no way to check if everything was valid before you post.

I have tried following:

Idea 1: Let OnBeforePost validate and throw an Exception

Idea 2: Throw an Exception in OnValidate

Idea 3: Show a (non-Exception) warning in OnValidate, and validate again in OnBeforePost (and throw an Exception)

Is there a better way?

Upvotes: 4

Views: 557

Answers (2)

Daniel Marschall
Daniel Marschall

Reputation: 3879

I have found the solution and posted it here:

https://www.viathinksoft.de/?page=codelib&showid=131

I will translate the explanation text when I have some more time.

Upvotes: 0

Torbins
Torbins

Reputation: 2216

It seems to me, that you are mixing business logic (data validation) with UI (OnValidate). Split them. Place all business logic in to separate functions or object. Probably it is even worth to implement MVC pattern. But in this case you will have to replace DB-controls with ORM framework + LiveBindings.

Upvotes: 1

Related Questions