How to amend an entry on a form without eliciting an EConvertError?
I have two labeled edit boxes - one for a min value (named
lbleRangeCalcMin) and the other for a max value (lbleRangeCalcMax). I want
to make sure that the user does not enter a zero for the max value and
also that the min value is less than the max value (not equal to, but less
than - I need the range of values: max - min).
I want to catch the error as soon as it happens (for e.g., as soon as the
user enters a zero for the max value). I also don't want the user to be
able to move away from the max value if s/he has entered a zero. So I have
programmed exception calls on the two events, OnChange and OnExit.
It works fine except when the user tries to reenter another value instead
of the zero that he entered. Then it gives me an EConvertError with the
message: '' is not a floating point value.
How do I allow the user to amend his entry without raising this exception?
Here is my code. Thanks.
procedure TfrmAnalysisOptions.lbleRangeCalcMaxChange(Sender: TObject);
begin
if ((StrToFloat((lbleRangeCalcMax.Text) = 0) or
(StrToFloat((lbleRangeCalcMax.Text) <
StrToFloat((lbleRangeCalcMin.Text))) then
MessageDlg('Max value cannot be zero or less than Min value.', mtError,
[mbOK], 0);
end;
procedure TfrmAnalysisOptions.lbleRangeCalcMaxExit(Sender: TObject);
begin
if ((StrToFloat(lbleRangeCalcMax.Text) = 0) or
(StrToFloat(lbleRangeCalcMax.Text) <
StrToFloat(lbleRangeCalcMin.Text))) then
MessageDlg('Max value cannot be zero or less than Min value.', mtError,
[mbOK], 0);
end;
No comments:
Post a Comment