LMD-Tools Validators Guide


Validated 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.

 

ILMDValidatedControl 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 of the validation mechanism. 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

TLMDValidationEntity

A reference to the Validator or Validation Group component assigned to the control

 

Methods (properties getters and setters omitted):

 

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 TLMDInPlaceErrorProvider 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: TLMDErrorLevel

none

Used by the TLMDInPlaceErrorProvider 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 ILMDValidatedControl interface support into a control are discussed in the How to Create a new validated control topic.

 

LMD demo - VCL validated controls

 

A set of Demo VCL Validated Controls is provided as examples of introducing ILMDValidatedControl interface support. This set includes the following controls:

 

LMDValidatedEdit;

LMDValidatedComboBox;

LMDValidatedDateTimePicker;

LMDValidatedDBComboBox;

LMDValidatedDBEdit;

LMDValidatedDBGrid;

LMDValidatedDBMemo;

LMDValidatedDBRichEdit;

LMDValidatedListBox;

LMDValidatedMaskEdit;

LMDValidatedMemo;

LMDValidatedRichEdit;

LMDValidatedStringGrid;

LMDValidationStatusBar.

 

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 Validators from the Validators collection property of the grid control is done by the Tag integer property of the TLMDValidatorItem items of the collection (Tag value is interpreted as the number of a column).

 

List, Label and StatusBar VCL-based controls support ILMDValidatingMsgControl interface and can be used as error messaging controls by TLMDControlErrorProvider.