Using TDBAdvEdit.OnValueValidate to inform the user that something is wrong with input text/value. That works fine. My dialog has a 'Cancel' button to cancel the changes and close the dataset. Cancelling the dataset isn't possible when there is a TDBAdvEdit not yet vaildated. The Cancel button event is fired after the OnValueValidate event, so setting some flag to catch the cancelling doesn't work. It's silly to restore changes to the field first and then cancel the dataset. Normally you only cancel the dataset. What can I do to change this ?
Also the OnValueValidate event "IsValid" is always True when EditType = etNumeric !
The validation is normally automatically performed when the focus leaves for the control.
So, if you edit a value and then the focus is lost due to pressing the Cancel button, the validate will happen first before the cancel click.
There is no easy solution. You could remove the validation handlers and assign these only when mrOK is done for the dialog and then for each editor call edit.Validate.
The isValid flag is not initialized or preset based on other criteria. It is always default true and is supposed to be set from the OnValueValidate event.
Sorry, but you are wrong. I have changed the source of TCustomAdvEdit.WMKillFocus:
if (EditType in [etNumeric]) and (Self.Text = '') and not FAllowNumericNullValue then // Text := '0'; IntValueInt := 0; if (EditType in [etFloat, etMoney]) and (Self.Text = '') and not FAllowNumericNullValue then FloatvalueInt := 0.0; // if (EditType = etNumeric) and ((FMinValue <> 0) or (FMaxValue <> 0)) then // begin // if AllowNumericNullValue and (Text = '') then // i := 0 // else // begin // try // i := StrToInt(Text); // except // i := 0; // end; // end; // // if i < MinValue then // Text := IntToStr(MinValue) // else // if i > MaxValue then // Text := IntToStr(MaxValue); // end; IsValid := DoValidate(Text);
With this changes "IsValid" works correct.
I cannot reproduce an issue.
Please isolate this and provide a sample source project so we know all settings & all code involved so we can reproduce this and investigate this.
UAdvEditControlsDemo.zip (11.8 KB)
I use the AdvEditControlsDemo to see the problem. There are two TAdvEdit controls, one is etNumeric and the other is etFloat edittype. Both have MaxValue at 100 and MinValue at -10 and OnValueValidate set. This event checks simple the IsValid param: if not IsValid then ShowMessage('Not Valid');
Just type let's say 9999 in the edit and then tab to the next control, with etNumeric the IsValid is always true, with etFloat it is not and the message shows. If I change the TAdvEdit source as mentioned then etNumeric behaves as expected. I hope this is clear enough ?
Thanks, this was now better understood and we improved the code for this.
The next update will have this improvement.