ParseInput

Unit: EgStrParser

// 1. Full form (thread-safe)
function ParseInput(const Input: string; ValueType: TInputType; RangeSep: Char;
  Options: TParseOptions; SqlOperator: TSqlOperator; SqlDialect: TSqlDialect): TParseResult; overload;
// 2. Uses the default dialect; RangeSep = '~'
function ParseInput(const Input: string; ValueType: TInputType;
  Options: TParseOptions; SqlOperator: TSqlOperator): TParseResult; overload;
// 3. Uses the default dialect; RangeSep = '~', SqlOperator = sopEqual
function ParseInput(const Input: string; ValueType: TInputType;
  Options: TParseOptions): TParseResult; overload;
// 4. Uses the default dialect; RangeSep = '~', Options = []
function ParseInput(const Input: string; ValueType: TInputType;
  SqlOperator: TSqlOperator): TParseResult; overload;
// 5. Minimal form; RangeSep = '~', Options = [], SqlOperator = sopEqual
function ParseInput(const Input: string; ValueType: TInputType): TParseResult; overload;

Parses the text typed by the user according to the declared data type and returns a TParseResult with the parsed values, their SQL literals and a ready SQL comparison fragment. It recognizes empty input, single values, lists (, or ;) and ranges (RangeSep) by itself.

Overload 1 takes every parameter, including the dialect, and is thread-safe. Overloads 2 to 5 are shorter forms that read the global default dialect set by SetSQLDialect (sqlElevateDB until it is called).

Parameters

Parameter Description
Input The raw text of the input control. It may contain spaces, quotes, list separators and the range separator.
ValueType The data type the input must represent: TInputType.
RangeSep The character between the two bounds of a range. Default '~'. It must not be ,, ;, -, +, ., /, :, a single quote, a letter, a digit, whitespace, a control character, or the locale date, time or decimal separator: these give ERR_INVALID_RANGESEP.
Options Processing options: TParseOptions. Default [].
SqlOperator The comparison operator of the SQL fragment: TSqlOperator. Default sopEqual.
SqlDialect The SQL dialect of the literals: TSqlDialect (overload 1 only).

Return value

A TParseResult. ResultType says what was found (otEmpty, otSingleValue, otList, otRange) or otInvalid; ErrorCode gives the reason of otInvalid. Invalid input never raises an exception; see Error handling. (The Demo edition raises EDemoRestriction when a restriction applies.)

Example

var
  R: TParseResult;
begin
  // 100~500, typed by the user
  R := ParseInput(edAmount.Text, itDecimal, '~', [opTrim], sopEqual, sqlMySQL);
  if R.ResultType in [otSingleValue, otList, otRange] then
    Query1.SQL.Text := 'SELECT * FROM Orders WHERE Amount ' + R.SQLExpression;
    // ... WHERE Amount BETWEEN 100 AND 500
end;

See Also

(C) 2026 Easygate, Lda