LMD Validators Pack |
Top Previous Next |
LMD Validators Pack introduces a set of components which allow implementation of professional-level client-side validation in an elegant and clear way without writing much code (often without any code at all).
The two main tasks of client-side validation are:
Consequently, there are three types of components involved into the most typical validation setup :
As for the input controls, most of the LMD edit controls (including their labeled and/or DB-aware versions) support validation since v. 7.1 of LMD Tools as they implement ILMDValidatedControl interface used by LMD Validators. There is also a demo package LMD Demo VCL Validated controls which includes validated (supporting ILMDValidatedControl interface) versions of most widely used standard VCL controls. Any third-party controls can be enabled to support validation by LMD Validators Package by implementing ILMDValidatedControl interface (see How to Create a new validated control topic for details).
Each of validated controls has the Validator property pointing to a Validator component which defines how values entered into this control should be validated. The ValidationMsg property gives control over the feedback message which is typically used by Error Provider component for error indication (see Validated input controls topic for details).
The special validation controls of the LMD Validators Pack can be divided in two groups:
Error Providers are connected to Validators using their Error Provider property. Validation Group component directly support multiple Error Providers with its ErrorProviders collection property; other validators can employ multiple error providers using the Error Providers Group component assigned to their Error Provider property.
So, the typical validation setup is the following: the validated input control MyControl has a MyValidator validator component assigned to its property; there's a MyProvider error provider assigned to the ErrorProvider property of MyValidator. Each time the value in the MyControl changes, the Validate function of MyValidator is called; if it returns a non-zero ErrorLevel value, it means that the value violates the validation rule (e.g. doesn't match a specified regular expression) and the DisplayError function of the MyProvider is called which performs some sort of error indication, e.g. displays a hint message which is generally assembled using the ErrorMessage property of MyValidator and the ValidationMsg property of MyControl. As DisplayError function gets MyControl reference as a parameter, the error indication can be performed in a control-specific way e.g. an icon is displayed near this control, or the hint is set for this control.
|