|
Technical answers from the trenches |
|
Verifying Data Values Before a Form Closes
| ||||
Posted: 1 October 2000 |
||||
  |
Applies to: Paradox 5.0 and later |
|||
  |
Audience: Everyone |
|||
Question: I would like to verify that my users have entered valid data before closing a form. How do I do this?Answer: One way is to verify the data when the menuAction() event is called with the menuCanClose menu action. MenuCanClose "fires" just before a form closes, regardless of how the close is triggered. The following code shows one way you might do this:
if eventinfo.id() = menuCanClose then
if not validateData() then
eventInfo.setErrorCode( userError )
endIf
endIf
If you're designing a dialog box, an alternate approach might be to move the validation into the pushbutton() event of your OK button. Here's one way you might do this:
doDefault ; paint the animation
if validateData() then
formReturn( TRUE )
endIf
We consider this a cleaner approach for dialog boxes because it moves the "business rule" reference (the validateData() call) close the the actual point it's actually needed. Thus, it gets called regardless of how the OK button gets triggered. In the end, it's really a stylistic choice. Use your best judgement. In the above code samples, validateData() refers to a custom method that you would add to validate your user's values. While the specific contents depends on your current needs, it needs to return a logical value (TRUE or FALSE) that indicates whether or not the close should be allowed to occur. ValidateData() should also display appropriate error messages. Please note that validation for records and field values is best performed with validation checks (or valchecks). If you apply a validation check, such as a Picture, a Min value, or a Max value, to the structure of your table, this will be enforced regardless of the form, process, or program used to enter data into your table. For an example, please see "Saving Values in Upper Case." |
|||
|
||||||||
|
Copyright © 2000-2004, techtricks.com; All Rights Reserved. Acknowledgements, Disclaimers, Terms and Conditions. |
||||||||
|
Article last updated on 31 May 2003
|
||
|
|
||
|
[- End -]
|