delphi - Combining OnValidate and OnBeforePost? -


as example, have form dbnavigator , few dbedits.

enter image description here

i want achive following:

  1. when user enters wrong in dbedit , wants switch control, warning should displayed, can continue working.
  2. when user wants post dataset, post rejected, , warning displayed again.

the problem is, onvalidate tfieldnotifyevent , therefore cannot tell application if edit valid, there no way check if valid before post.

i have tried following:

idea 1: let onbeforepost validate , throw exception

  • pro:
    • invalid data not posted
    • the user can continue working , revert changes using dbnavigator if cannot complete form.
  • contra:
    • no warning displayed when user leaves dbedit
    • (low priority) validations have in 1 single point. better object orientated if validate done directly in tfield.

idea 2: throw exception in onvalidate

  • pro:
    • it impossible post invalid data.
  • contra:
    • the user might stay in endless loop if unable enter valid (e.g. because doesn't know enter), , cannot press "revert" button on dbnavigator! in case, has kill application using task manager, worst-case-scenario in regards user-friendliness.

idea 3: show (non-exception) warning in onvalidate, , validate again in onbeforepost (and throw exception)

  • pro:
    • warning possible, , invalid data cannot posted.
  • contra:
    • the check has implemented twice (even if outsourced function), , there risk developer might forget 1 of these 2 checks. also, big projects many fields validate, gets confusing.
    • when user clicks post-button while being in dbedit, gets message twice (one warning leaving dbedit, , 1 exception because post fails)
    • in case data is wrong in database, when dataset loaded (e.g. because of older program version didn't check value), post allowed (if user didn't edit value in session)

is there better way?

it seems me, mixing business logic (data validation) ui (onvalidate). split them. place business logic in separate functions or object. worth implement mvc pattern. in case have replace db-controls orm framework + livebindings.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -