TsCustomNumEdit.SetText does no validity check

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #69709
    HeDiBo
    Participant

    This procedure is wrong at the indicated place:

    procedure TsCustomNumEdit.SetText(const AValue: string);
    begin
      if not (csReading in ComponentState) then begin
        // If AValue is empty, the following statement throws an exception:
        FValue := CheckValue(StrToFloat(TextToValText(AValue)));
        //                   ^^^^^^^^^^   Exception!
        DataChanged;
        SkinData.Invalidate;
      end;
    end;

    The error occurs if the ShowZeroIfEmpty property is False.

    #69710
    HeDiBo
    Participant

    I think the procedure should read:

    procedure TsCustomNumEdit.SetText(const AValue: string);
    var
      Val:  String;
    begin
      if not (csReading in ComponentState) then begin
        Val := TextToValText(AValue);
        if Val <> '' then FValue := CheckValue(StrToFloat(Val))
                     else FValue := 0;
        DataChanged;
        SkinData.Invalidate;
      end;
    end;

    But again: this stems from a TsDBCalcEdit control that’s being filled from the database. Not by the user. Why do you want to do a CheckValue in that case? What possible correction can the user make if the Min/Max message pops up? He/she is not editing the field at that time, program logic may even prohibit editing of the field!

    #69711
    HeDiBo
    Participant

    I think function TsCustomNumEdit.CheckValue should should start off like this:

    begin
      Result := NewValue;
      if not Modified then Exit;   // Accept any value if field is not entered by user
      if FMaxValue <> FMinValue then
    .
    .
    .

    That would not cure the Conversion error above, but would once and for all get rid of unmanageable data errors.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.