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.
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.
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.
精彩评论