LMD-Tools Validators Guide


Multiple Error Providers


How to use multiple ErrorProviders for a control? The most natural solution is to use an Error Providers Group as the Error Provider for the Validator of this control. Let's consider the same example as in How to use multiple validators for a control walk-through, but so that possible errors are to be indicated in the following ways:

 

1.if LMDEdit1 is empty, a message box should be displayed;

2.if LMDEdit1 doesn't contain a valid email address, a message should be displayed by a LMDSimpleLabel1 label component;

3.if the value in LMDEdit1 doesn't match the value in LMDEdit2, a hint for this control should be displayed.

 

It can be achieved by use of Error Providers Group component which references three Validator components:

 

1.TLMDMessageBoxErrorProvider

2.TLMDControlErrorProvider

3.TLMDHintErrorProvider

 

The following steps have to be performed:

 

1.Place TLMDMessageBoxErrorProvider component (LMDMessageBoxErrorProvider1) on a form; set its MaxErrorLevel and MinErrorLevel properties to 3.

2.Place TLMDControlErrorProvider component (LMDControlErrorProvider1) on a form; set its MaxErrorLevel and MinErrorLevel properties to 2, its ErrMsgControl property to LMDSimpleLabel1;

3.Place TLMDHintErrorProvider component (LMDHintErrorProvider1) on a form; set its MaxErrorLevel and MinErrorLevel properties to 1;

4.Place TLMDErrorProvidersGroup component (LMDErrorProvidersGroup1) on a form

4.1. Add an item to its ErrorProviders collection, set its ErrorProvider property to LMDMessageBoxErrorProvider1;

4.2. Add an item to its ErrorProviders collection, set its ErrorProvider property to LMDControlErrorProvider1;

4.3. Add an item to its ErrorProviders collection, set its ErrorProvider property to LMDHintErrorProvider1;

5.Perform steps 2-5.3 from How to use multiple validators for a control walk-through;

6.Add an item to the ErrorProviders collection of LMDValidationGroup1, set its ErrorProvider property to LMDErrorProvidersGroup1

 

Now the errors in field LMDEdit1 should be indicated as formulated above.

 

Note: In this example Error Provider components could be added directly to the ErrorProviders collection of LMDvalidationGroup1. However, if not a Validation Group but a single Validator is used for a control, use of Error Providers Group is the best option.