NG ValidatorPack Guide


Validated Input Controls


NG ValidatorsPack introduces a set of components that represent validated (supporting INGValidatedControl interface) versions of most widely used standard VCL controls. Any third-party or custom controls can be enabled to support validation by NG ValidatorsPack by implementing INGValidatedControl 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.

 

INGValidatedControl interface

 

ILMDValidatedControl interface is to be supported by all the validation-enabled controls. It defines some properties and methods used by Validators and Error Providers components. These properties and methods are listed in the tables below.

 

Properties

 

Name

Type

Description

Control

TControl

A read-only reference to the validated control; typically just points to the control itself (can be different for complex controls aggregating other controls)

ControlBackBrush

TBrush

A read-only reference to the brush of the control's background; used for the default in-place error indication (which changes control's back color). If the control does not support default way of in-place error indication (SupportsDefaultIndication function returns False) this property can be a nil reference

ControlFont

TFont

A read-only reference to the font of the control; used for the default in-place error indication (which changes control's font). If the control does not support default way of in-place error indication (SupportsDefaultIndication function returns False) this property can be a nil reference

ValidationMsgString

string

A string used for error-indicating message. Typically should contain a name of the data field (e.g. 'First name', 'Address') represented by the control. Is substituted to the %F placeholder in the ErrorMessage property of the validator component by its GetMessage function.

Validator

TNGValidationEntity

A reference to the validator (or validation group) component assigned to the control.

 

Methods

 

Name

Parameters

Result type

Description

GetValueToValidate

none

string

Used by Validator Components to obtain the value to be validated. Typically should return the value of the Text property of a control.

SupportsDefaultIndication

none

Boolean

Determines if the control supports default way of in-place error indication. Used by the TNGInPlaceErrorProvider component. If this function returns True, ControlBackBrush and ControlFont properties should provide a non-nil meaningful values. If this function returns False, the RespondToError procedure should perform some actions to modify control's look correspondingly to the passed value of ErrorLevel.

RespondToError

ErrorLevel: TNGErrorLevel

none

Used by the TNGInPlaceErrorProvider component. If SupportsDefaultIndication function returns False, this procedure should perform some actions to modify control's look correspondingly to the passed value of ErrorLevel.

 

Aspects of introducing INGValidatedControl interface support into a control are discussed in the How to Create a New Validated Control topic.

 

Example validation aware controls

 

A set of controls is provided as examples of introducing INGValidatedControl interface support. This set includes the following controls:

 

NGValidatedEdit;

NGValidatedComboBox;

NGValidatedDateTimePicker;

NGValidatedDBComboBox;

NGValidatedDBEdit;

NGValidatedDBGrid;

NGValidatedDBMemo;

NGValidatedDBRichEdit;

NGValidatedListBox;

NGValidatedMaskEdit;

NGValidatedMemo;

NGValidatedRichEdit;

NGValidatedStringGrid;

NGValidationStatusBar.

 

The grid controls demonstrate some non-typical features of validation support e.g. Validators can be assigned to each of the columns of the gird; mapping of the vValidators from the Validators collection property of the grid control is done by the Tag integer property of the TNGValidatorItem items of the collection (Tag value is interpreted as the number of a column).

 

List, label and status bar VCL-based controls support ILMDValidatingMsgControl interface and can be used as Error Messaging Controls by TNGControlErrorProvider.