views:

123

answers:

2

Hi,

I have an application, where there are many forms which follow visual form inheritance. Every form has standard delphi components as well as custom components.

Form validating functionality needs to be added. That is, A small red circle or astric image needs to be drawn next to a control, if the control's value is not valid.

This drawing functionality has to be available through out the application on every control.

What is the best way of implementing this functionality? Is there any design pattern that can help?

Thanks & Regards, Pavan.

+4  A: 

JEDI's JVCL has the TJvValidator component that will do just that for you. Here's a link to the TJvValidators container to get you started.

Ken White
But beware: This component is difficult to understand without an example (but there is one in the jvcl installation), the validators that come with the jvcl are mostly useless and depending on how often it is called it will slow down your GUI code. But the concept is nice.
dummzeuch
+1  A: 

Something I have done in the past in my validate method was to change the control color to $00C4C4FF for any value which fails validation, or clWindow if it passes. (I use a constant clInvalidEdit). On projects where I am also using Raize controls with a flat border, I also adjust the border to clRed. My required fields generally have a color of $00B0FFFF (again a constant clRequiredEdit).

Most often, I'll create a method named ValidateForm which returns a boolean if the form is valid, or false if its not. The validateform checks every field for validity and adjusts colors where needed, and set the active control to the first field which fails.

skamradt
Can we have some custom behavior instead of changing the values of existing control properties. Again, like drawing red circle next to the control. And the big thing is this approach need to work for every control on form, derived or not derived.
Pavan