Ga naar inhoud

TP2WDAQuery

TP2WDAQuery is a TDataSet descendant that will use your TP2WDARemoteAdapter and contain rows of actual data.

TP2WDAQuery fully supports DA SQL and as such allows for you to send complex queries to server.

Properties

property description
Active Specifies whether or not this TP2WDAQuery is open
Adapter You must link this property up to a TP2WDARemoteAdapter component for your TP2WDAQuery to retrieve (and potentially update) data.
Params Contains the parameters for this TP2WDAQuery's SQL statement.
SQL Contains the text of the SQL statement to execute for the query.

Let's assume you have a need for the following query, joining two tables in the schema associated with your DataService:

SELECT m.Id, p.FirstName, p.LastName FROM planning.teammembers AS m JOIN crm.persons AS p ON p.Id = m.PersonId WHERE m.TeamId = @TeamId

The above SQL statement includes a parameter named @TeamId. Here is how you could set this parameter before you activate and open your TP2WDAQuery:

procedure TForm1.TeamMemberChange(const TeamId: Integer);
begin
  if TeamId > -1 then
  begin
    Query.Close;
    try
      Query.SetParam('TeamId', TeamId);
    finally
      Query.Open;
    end;
  end;
end;

Methods

Because TP2WDAQuery is derived from TDataSet, it includes these methods.

In addition to the methods derived from TDataSet, TP2WDAQuery includes a method named WaitForOpen that you can use in the following manner:

procedure TForm1.DoSomething; async;
begin
  Query.Active := True;
  try
    if await(Boolean, Query.WaitForOpen) then
    begin
      Query.First;
      while not Query.EOF do
      begin
        ...
        Query.Next;
      end;
    end;
  finally
    Query.Active := False;
  end;
end;

Events

event description
BeforeApplyUpdates Fires just before this TP2WDAQuery will apply updates to the server.
BeforeClose Fires just before this TP2WDAQuery will be effectively closed.
BeforeOpen Fires just before this TP2WDAQuery will be effectively opened.
BeforeScroll Fires just before a scroll will happen in this TP2WDAQuery.
AfterApplyUpdates Fires after this TP2WDAQuery has applied updates to the server.
AfterClose Fires after this TP2WDAQuery got closed.
AfterOpen Fires after this TP2WDAQuery got opened.
AfterScroll Fires after this TP2WDAQuery's cursor scrolled to another record.
OnError Fires when an error occurs while loading, deleting, or updating data. If you don't handle this event, it is possible for this TP2WDAQuery to raise an exception.