From: <ah...@us...> - 2007-01-20 11:41:05
|
Revision: 11159 http://svn.sourceforge.net/jvcl/?rev=11159&view=rev Author: ahuser Date: 2007-01-20 03:41:00 -0800 (Sat, 20 Jan 2007) Log Message: ----------- Added property ErrorControl: TControl that is used for the error indicator if set. Modified Paths: -------------- trunk/jvcl/run/JvValidators.pas Modified: trunk/jvcl/run/JvValidators.pas =================================================================== --- trunk/jvcl/run/JvValidators.pas 2007-01-20 11:39:57 UTC (rev 11158) +++ trunk/jvcl/run/JvValidators.pas 2007-01-20 11:41:00 UTC (rev 11159) @@ -70,9 +70,11 @@ FPropertyToValidate: string; FErrorMessage: string; FControlToValidate: TControl; + FErrorControl: TControl; FValidator: TJvValidators; FOnValidateFailed: TNotifyEvent; procedure SetControlToValidate(Value: TControl); + procedure SetErrorControl(Value: TControl); protected function GetValidationPropertyValue: Variant; virtual; procedure SetValid(const Value: Boolean); virtual; @@ -101,6 +103,8 @@ property Value: Variant read GetValidationPropertyValue; published property Valid: Boolean read GetValid write SetValid; + // the control that is used to align the error indicator (nil means that the ControlToValidate should be used) + property ErrorControl: TControl read FErrorControl write SetErrorControl; // the control to validate property ControlToValidate: TControl read FControlToValidate write SetControlToValidate; // the property in ControlToValidate to validate against @@ -325,6 +329,7 @@ destructor TJvBaseValidator.Destroy; begin Debug('TJvBaseValidator.Destroy: FValidator is %s', [ComponentName(FValidator)]); + ErrorControl := nil; ControlToValidate := nil; if FValidator <> nil then begin @@ -406,8 +411,12 @@ begin inherited Notification(AComponent, Operation); if Operation = opRemove then + begin if AComponent = ControlToValidate then ControlToValidate := nil; + if AComponent = ErrorControl then + ErrorControl := nil; + end; end; procedure TJvBaseValidator.SetValid(const Value: Boolean); @@ -435,6 +444,18 @@ end; end; +procedure TJvBaseValidator.SetErrorControl(Value: TControl); +begin + if FErrorControl <> Value then + begin + if FErrorControl <> nil then + FErrorControl.RemoveFreeNotification(Self); + FErrorControl := Value; + if FErrorControl <> nil then + FErrorControl.FreeNotification(Self); + end; +end; + procedure TJvBaseValidator.SetParentComponent(Value: TComponent); begin if not (csLoading in ComponentState) then @@ -685,6 +706,7 @@ var I: Integer; Controls: TList; + ErrCtrl: TControl; begin Result := True; if ValidationSummary <> nil then @@ -710,10 +732,14 @@ begin if (Items[I].ErrorMessage <> '') and (Items[I].ControlToValidate <> nil) then begin + ErrCtrl := Items[I].ErrorControl; + if ErrCtrl = nil then + ErrCtrl := Items[i].ControlToValidate; + if ValidationSummary <> nil then FValidationSummary.AddError(Items[I].ErrorMessage); if ErrorIndicator <> nil then - FErrorIndicator.SetError(Items[I].ControlToValidate, Items[I].ErrorMessage); + FErrorIndicator.SetError(ErrCtrl, Items[I].ErrorMessage); if FErrorIndicator <> nil then Controls.Remove(Items[I].ControlToValidate); { control is not valid } end; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |