Skip to content
Carlo Barazzetta edited this page Dec 4, 2018 · 5 revisions

Using an InstantQuery

TInstantQuery is not available in Delphi's Component or Tool Palette,but it is useful to fetch a list of objects from the storage through anIQL statement. TInstantQuery basically represents the core of  theSelector.

TInstantQuery is an abstract class. What you actually use are concrete descendant classes, which you instantiate through the connector's CreateQuery method. The advantage in using a TInstantQuery descendant lies directly in the lower overhead, as there is no TDataSet buffer management involved. So, if you want to fetch objects and don't have a data-aware presentation layer, TInstantQuery is the preferred way to do it. 

Example

function CompanyOfCityCount(const ACityId: string): Integer;
begin
  with InstantDefaultConnector.CreateQuery do
  try
    Command := 'SELECT * FROM ANY TCompany WHERE City = :City';
    // Since this is a parameterized query, fetch the param definitions.
    FetchParams(InstantQuery.Command, InstantQuery.Params);
    // Set the param values
    Params.ParamByName('City').AsString := ACityId;
    Open;
    Result := ObjectCount;
  finally
    Free;
  end;
end;
Clone this wiki locally