Delphi help with validation

Mobster
Soldato
Joined
9 Apr 2012
Posts
13,151
So I'm forced to use Delphi for this project and I need some help :)

Essentially the user enters coefficients for a constant all the way up to a sextic. These coefficients are validated using a regular expression and if they are valid, then they are converted using StrToFloat.

There is one form (GetFunction) where the user enters the coefficients and on clicking okay, if the coefficients are all valid (out of those which are enabled - done using checkboxes), then the graph is created on the second form (GraphingMode).

The issue I am having is keeping the GetFunction form visible until valid input is received. Currently I have it setup like this:

Code:
procedure TfrmGetFunction.btnAddFunctionClick(Sender: TObject);
  var
    i : integer; // Loop counter.
  begin
    for i := 1 to 7 do
      begin
        CoefficientEdit[i].CoValid := CheckCoefficientBoxesValidInput(CoefficientEdit[i].CoEditBox);
        if not CoefficientEdit[i].CoValid then // If any input box is invalid.
          Exit;
      end;
    frmGraphingMode.CreateGraph(1.001); // Finally if all input boxes valid.
    frmGetFunction.Visible := false;
    frmGraphingMode.Visible := true;
  end;

I am having to use the Exit command which I'm told is a bad idea as it makes the program less structured than it could be.

How do I do this then without using Exit?
 
In that case perhaps people say it's a bad idea because the invalid input needs to be handled somehow with feedback to the user?

I can easily give feedback to the user using this, I think it's because you're essentially exiting a function/procedure without it naturally coming to an end.

I'm just looking for a way to show the GetFunction form until valid input is found in all the input boxes basically :)
 
Back
Top Bottom