Error handling

When ParseInput cannot produce a valid result, it sets ResultType to otInvalid and returns a non-zero value in ErrorCode. Every error is reported this way: ParseInput does not raise exceptions for invalid input. ResultType is otInvalid if and only if ErrorCode is not ERR_NONE, and then SQLExpression is empty.

Error codes

Constant Value Condition
ERR_NONE 0 Success.
ERR_INVALID_FORMAT 1 A token cannot be converted to the declared input type.
ERR_INVALID_RANGE 2 The left bound of a range is greater than the right bound.
ERR_LIST_SEPARATOR_CONFLICT 3 The input has both a list separator and the range separator.
ERR_NULL_NOT_ALLOWED 4 opNotNull is set and a token became NULL.
ERR_EMPTY_NOT_ALLOWED 5 opRequired is set and the input is empty.
ERR_INVALID_RANGESEP 6 The range separator is a reserved character.

For an error found after the tokens were parsed (range order, opNotNull), Values and SQLValues keep the parsed tokens, which can be used in the error message. For the other errors (format, ERR_LIST_SEPARATOR_CONFLICT, ERR_INVALID_RANGESEP) they are empty (nil), and so is ParsedValue.

Handling errors

Check ResultType first, then use ErrorCode for the message:

R := ParseInput(Edit1.Text, itDate, [opRequired]);
case R.ResultType of
  otEmpty:
    ; // no input: no condition on this field
  otInvalid:
    case R.ErrorCode of
      ERR_EMPTY_NOT_ALLOWED:
        ShowMessage('Please enter a date.');
      ERR_INVALID_FORMAT:
        ShowMessage('The date format was not recognized.');
      ERR_INVALID_RANGE:
        ShowMessage('The start date must not be later than the end date.');
    else
      ShowMessage('Invalid input (error ' + IntToStr(R.ErrorCode) + ').');
    end;
else
  Query1.SQL.Text := 'SELECT * FROM Orders WHERE OrderDate ' + R.SQLExpression;
  Query1.Open;
end;

Demo edition

The Demo edition raises EDemoRestriction when the input is longer than DEMO_MAX_INPUT_LENGTH or the Delphi IDE is not running. The Standard and Pro editions never raise it.

See Also

(C) 2026 Easygate, Lda