I am stuck a bit. My aim is to check and validate my currency field always when it's value changed never mind from the inline code or from the user interface. Is there any validation pattern or sample for it? I want to avaiod calling my validation procedure twice.
Any help or advice would be greatly appreciated.
Here is my example:
type
TMyForm = class(TForm)
ceMyCurrencyEdit: TcxCurrencyEdit;
procedure FormShow(Sender: TObject);
private
{ Private declarations }
procedure SetupMyForm;
public
{ Public declarations }
procedure ValidateMyCurrencyValue;
function IsValidCurrency: Boolean;
end;
procedure TMyForm.ValidateMyCurrencyField;
begin
if not IsValidCurrency then
begin
WarningDlg(
Format(
'InValid value in field: [%s..%s]',
[Formatfloat(ceMyCurrencyEditDisplayFormat, ceMyCurrencyEdit.MinValue),
Formatfloat(ceMyCurrencyEdit.DisplayFormat, ceMyCurrencyEdit.MaxValue)]
)
);
ceMyCurrencyEdit.Value := ceMyCurrencyEdit.MinValue;
end;
end;
function TMyForm.IsValidCurrency: Boolean;
begin
Result := (ceMyCurrencyEdit.Value >= ceMyCurrencyEdit.MinValue) and (ceMyCurrencyEdit.Value <= ceMyCurrencyEdit.MaxValue);
end;
procedure TMyForm.SetupMyForm;
begin
//MaxValue is 100
ceMyCurrencyEdit.Value := 102;
//At this point I need to call ValidateMyCurrencyField to get warning msg and refuse its value
ValidateMyCurrencyField;
end;
procedure TMyForm.FormShow(Sender: TObject);
begin
SetupMyForm;
end;
procedure TMyForm.ceMyCurrencyEditPropertiesEditValueChanged(Sender: TObject);
begin
ValidateMyCurrencyField;
end;
What I want is...
Thanks for the answers!