Error codes

When ParseInput cannot produce a valid result, it sets ResultType to otInvalid and returns a non-zero value in ErrorCode. All error conditions are reported this way; ParseInput never raises an exception in release builds.

Error code reference

Constant Value Condition
ERR_NONE 0 Success. No error.
ERR_INVALID_FORMAT 1 A token could not be converted to the declared TInputType.
ERR_INVALID_RANGE 2 The left range bound is greater than the right bound.
ERR_LIST_SEPARATOR_CONFLICT 3 Both a list separator (, or ;) and the range separator were found in the same input.
ERR_NULL_NOT_ALLOWED 4 opNotNull was set and at least one token resolved to NULL.
ERR_EMPTY_NOT_ALLOWED 5 opRequired was set and the whole input was empty.
ERR_INVALID_RANGESEP 6 The RangeSep character is one of the reserved characters: ,, ;, -, ., ' (single quote), or space.

ERR_INVALID_FORMAT (1)

The input contains a token that cannot be parsed as the declared type.

Common causes:

R := ParseInput('3.14', itInteger);
// R.ResultType = otInvalid
// R.ErrorCode  = ERR_INVALID_FORMAT

ERR_INVALID_RANGE (2)

Applies to itInteger, itDecimal, itFloat, itDate, itTime, and itDateTime when the input is a range and the left bound is strictly greater than the right bound.

itString and itBoolean ranges are never order-checked.

R := ParseInput('100~1', itInteger);
// R.ResultType = otInvalid
// R.ErrorCode  = ERR_INVALID_RANGE

R := ParseInput('2026-12-31~2026-01-01', itDate);
// R.ResultType = otInvalid
// R.ErrorCode  = ERR_INVALID_RANGE

Equal bounds are allowed: 10~10 produces BETWEEN 10 AND 10.

ERR_LIST_SEPARATOR_CONFLICT (3)

The input contains both a list separator (, or ;) and the range separator outside quoted regions. The parser cannot determine whether the input is a list or a range.

R := ParseInput('1,2~3', itInteger);
// R.ResultType = otInvalid
// R.ErrorCode  = ERR_LIST_SEPARATOR_CONFLICT

This error can be avoided by using a range separator that does not appear in the input, or by quoting values that contain the conflicting characters.

ERR_NULL_NOT_ALLOWED (4)

opNotNull was set and at least one token in the output resolved to NULL. This happens when a list position is empty (1,,3), a range bound is empty (~100), or the whole input is empty for a non-string type.

For itString, empty tokens produce '' (not NULL) unless opEmptyStringNull is also set.

R := ParseInput('1,,3', itInteger, [opNotNull]);
// R.ResultType = otInvalid
// R.ErrorCode  = ERR_NULL_NOT_ALLOWED

ERR_NULL_NOT_ALLOWED is not set when ERR_EMPTY_NOT_ALLOWED has already been returned for the same call.

ERR_EMPTY_NOT_ALLOWED (5)

opRequired was set and the whole input (after opTrim when present) is empty or whitespace only.

R := ParseInput('', itDate, [opRequired]);
// R.ResultType = otInvalid
// R.ErrorCode  = ERR_EMPTY_NOT_ALLOWED

R := ParseInput('   ', itDate, [opRequired, opTrim]);
// R.ResultType = otInvalid
// R.ErrorCode  = ERR_EMPTY_NOT_ALLOWED

ERR_INVALID_RANGESEP (6)

The RangeSep character passed to ParseInput overload 1 is one of the reserved characters: ,, ;, -, ., ' (single quote), or space. These characters are reserved because they are used by other parts of the parser:

When this error occurs, SQLExpression is empty and Values and SQLValues are nil.

R := ParseInput('a,b', itString, ',', [], sopEqual, sqlElevateDB);
// R.ResultType = otInvalid
// R.ErrorCode  = ERR_INVALID_RANGESEP

Handling errors

The recommended pattern is to check ResultType first, then branch on ErrorCode for user-facing messages:

R := ParseInput(Edit1.Text, itDate, [opRequired]);
case R.ResultType of
  otEmpty:
    ; // no input; no WHERE clause needed
  otInvalid:
    case R.ErrorCode of
      ERR_EMPTY_NOT_ALLOWED:
        ShowMessage('Please enter a date.');
      ERR_INVALID_FORMAT:
        ShowMessage('The date format was not recognised.');
      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;

ParseInput never raises an exception for invalid input in release builds. The EDemoRestriction exception is raised only by demo builds when the input exceeds the demo length limit or when the Delphi IDE is not running.

(C) 2026 Easygate, Lda