RxCloseFormvalidate - add OnValidate event for item custom validate rule

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2761 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75 2013-07-09 18:46:44 +00:00
parent fa1ffd579f
commit eeb03913ca

View File

@ -39,6 +39,9 @@ uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DB; Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DB;
type type
TRxCloseFormValidator = class;
TValidateEvent = procedure(AOwner:TRxCloseFormValidator; AControl:TWinControl; var Validate:boolean) of object;
{ TValidateItem } { TValidateItem }
@ -47,6 +50,7 @@ type
FControl: TWinControl; FControl: TWinControl;
FEnabled: boolean; FEnabled: boolean;
FFieldCaption: string; FFieldCaption: string;
FOnValidate: TValidateEvent;
procedure SetControl(AValue: TWinControl); procedure SetControl(AValue: TWinControl);
procedure SetEnabled(AValue: boolean); procedure SetEnabled(AValue: boolean);
procedure SetFieldCaption(AValue: string); procedure SetFieldCaption(AValue: string);
@ -63,6 +67,7 @@ type
property Control:TWinControl read FControl write SetControl; property Control:TWinControl read FControl write SetControl;
property Enabled:boolean read FEnabled write SetEnabled default true; property Enabled:boolean read FEnabled write SetEnabled default true;
property FieldCaption:string read FFieldCaption write SetFieldCaption; property FieldCaption:string read FFieldCaption write SetFieldCaption;
property OnValidate:TValidateEvent read FOnValidate write FOnValidate;
end; end;
{ TValidateItems } { TValidateItems }
@ -72,7 +77,6 @@ type
function GetItems(Index: Integer): TValidateItem; function GetItems(Index: Integer): TValidateItem;
procedure SetItems(Index: Integer; AValue: TValidateItem); procedure SetItems(Index: Integer; AValue: TValidateItem);
public public
//constructor Create();
property Items[Index: Integer]: TValidateItem read GetItems write SetItems; default; property Items[Index: Integer]: TValidateItem read GetItems write SetItems; default;
end; end;
@ -237,29 +241,35 @@ var
begin begin
Result:=true; Result:=true;
if not Assigned(FControl) then exit; if not Assigned(FControl) then exit;
if FControl = AForm.ActiveControl then
begin if Assigned(FOnValidate) then
AForm.SelectNext(FControl, true, true); FOnValidate( TRxCloseFormValidator(TValidateItems(Collection).Owner), FControl, Result)
end;
//Сначала проверим - вдруги это завязки на работу с БД
PI1:=GetPropInfo(Control, 'DataSource');
PI2:=GetPropInfo(Control, 'DataField');
if Assigned(PI1) and Assigned(PI2) then
begin
//Точно - БД
//Проверка выполняется если только указан источник данных и поле в нём
P:=GetObjectProp(Control, 'DataSource');
FiName:=GetPropValue(Control, 'DataField');
if Assigned(P) and (FiName<>'') then
begin
DS:=(P as TDataSource).DataSet;
if Assigned(DS) then
Result:=not DS.FieldByName(FiName).IsNull;
end;
end
else else
if Control is TCustomEdit then begin
Result:=TCustomEdit(Control).Text<>''; if FControl = AForm.ActiveControl then
begin
AForm.SelectNext(FControl, true, true);
end;
//Сначала проверим - вдруги это завязки на работу с БД
PI1:=GetPropInfo(Control, 'DataSource');
PI2:=GetPropInfo(Control, 'DataField');
if Assigned(PI1) and Assigned(PI2) then
begin
//Точно - БД
//Проверка выполняется если только указан источник данных и поле в нём
P:=GetObjectProp(Control, 'DataSource');
FiName:=GetPropValue(Control, 'DataField');
if Assigned(P) and (FiName<>'') then
begin
DS:=(P as TDataSource).DataSet;
if Assigned(DS) then
Result:=not DS.FieldByName(FiName).IsNull;
end;
end
else
if Control is TCustomEdit then
Result:=TCustomEdit(Control).Text<>'';
end;
end; end;
function TValidateItem.ErrorMessage: string; function TValidateItem.ErrorMessage: string;