Pass Ifddatasetreference (Firedac) to Clientdataset.Data

Asked

Viewed 963 times

0

I have a Query of Firedac (Fdquery) and want to pass its result to a Clientdataset.

Since Firedac works with Ifddatasetreference and the Clientdataset work with Olevariant, of the compatibility error. Code that generates the error:

  ClientDataSet1.Data := FDQuery1.Data;

Error presented: Invalid data Packet.

How can I do that?
Important details:

  • It has to be Clientdataset, in which case it can’t be Fdmemtable.
  • I don’t want/I can browse the query with a While to pass to the
    Clientdataset.

2 answers

2


clientDataSet has to have exactly the same query structure ?

In this case you must use a component called DataSetProvider,

Follow an example of use :

procedure TForm1.FormCreate(Sender: TObject);
begin
  FDQuery1.SQL.Text := 'select * from tbClientes';
  DataSetProvider1.DataSet := FDQuery1;
  ClientDataSet1.ProviderName := DataSetProvider1;
  ClientDataSet1.Active := true; // cds que abre a query
  FDQuery1.close; //Query pode ser fechada, o clientDataSet irá armazenar os dados.
end;

Remember that using a Preview, the Database client is in charge of opening the query.

-1

Use query.data.

Use your client.data := your query.data, the data property returns the data dataset.

function TRegra.ListarTitulosAVencer(pInicial, pFinal: TDate): TFDQuery;
begin
  with Query do begin
    SQL.Clear;
    SQL.Add(MontaSQL(1));
    Regras.Geral.Parametro(Query, 'DataInicial', ftDate, pInicial);
    Regras.Geral.Parametro(Query, 'DataFinal', ftDate, pFinal);
    Open;
    result := Query;
  end;
end;

To use

var vRegra: TRegra;
begin
  inherited;
  vRegra := TRegra.Create;
  dsGrid.DataSet := nil;
  MemGrid.Data := vRegra.ListarTitulosAVencer(Inicial, Final).Data;
  dsGrid.Dataset := MemGrid;
  FreeAndNil(vRegra);
end;
  • As I mentioned in the question, I already do that and that’s what causes the error. Anyway, thanks for trying to help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.