Using EgStrParser

EgStrParser has two units:

Unit Declares Depends on
EgStrParser ParseInput, SetSQLDialect, GetSQLDialect, the types, TParseResult and the constants the RTL only (System.SysUtils, System.StrUtils, System.Types)
EgStrParserComp the TEgStrParser component System.Classes and EgStrParser

Neither depends on VCL or FMX: they can be used in any Delphi application, including services and console applications.

As a library

Add EgStrParser to the uses clause and call ParseInput with the raw text of the input control and the expected data type:

uses
  EgStrParser;

var
  R: TParseResult;
begin
  R := ParseInput(Edit1.Text, itDate);
  if R.ResultType <> otInvalid then
    Query1.SQL.Text := 'SELECT * FROM Orders WHERE OrderDate ' + R.SQLExpression;
end;

ParseInput always returns a TParseResult and never raises an exception for invalid input. ResultType says what the parser found (empty input, a single value, a list or a range); ErrorCode gives the reason when ResultType is otInvalid. See Error handling.

The format of date, time, date-time and boolean literals depends on the target database. The dialect is set once per application with SetSQLDialect, or given in each call to the full overload of ParseInput. The default is sqlElevateDB. See SQL dialects.

As a component

TEgStrParser is a non-visual component that wraps ParseInput. Drop it from the Easygate category of the Tool Palette on a form or data module, set SqlDialect, DefaultOptions, DefaultRangeSep and DefaultOperator once in the Object Inspector, and call Parse from event handlers:

procedure TfrmSearch.edNameExit(Sender: TObject);
var
  R: TParseResult;
begin
  R := EgParser1.Parse(edName.Text, itString, sopLikeRight, Sender as TComponent);
  if R.ResultType <> otInvalid then
    FNameFilter := 'CustomerName ' + R.SQLExpression;
end;

One component is usually enough for a whole form; use more only when parts of the form need different dialects or default operators.

When the component is dropped on a form, the IDE adds EgStrParserComp to the uses clause, but not EgStrParser. A unit that names TParseResult, TInputType, TSqlOperator, TParseOptions, otInvalid or any ERR_* constant must list EgStrParser in its own uses clause.

The component never reads the text of a control itself: the caller always passes it. The property that holds the value depends on the control (Text, ItemIndex, Value…), and only the caller knows which one applies.

Library or component

Use the library when no component is wanted, or in worker threads with an explicit dialect in each call. Use the component to keep the dialect and the defaults of a form in one place, set at design time. Both use the same engine and give the same results. See Thread safety.

See Also

(C) 2026 Easygate, Lda