Pass IFDDatasetReference (Firedac) to ClientDataSet.Data

0

I have a Query of FireDAC ( FDQuery ) and want to pass its output to a ClientDataSet .

Since FireDAC works with IFDDataSetReference and ClientDataSet work with OleVariant , the compatibility error. Code that generates error:

  ClientDataSet1.Data := FDQuery1.Data;

Error presented: Invalid data packet .

How can I do this? Important details:

  • It must be the ClientDataSet, in which case it can not be FDMemTable.
  • I do not want / can go through Query with a While to go to
    ClientDataSet.
asked by anonymous 03.04.2017 / 19:38

2 answers

2

Does clientDataSet have exactly the same structure as the query?

In this case you should use a component called DataSetProvider ,

Here is an example usage:

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;

Remembering that by using a provider, clientDataSet is in charge of opening the query.

    
18.10.2017 / 18:11
-1

Use query.data.

Use seuclient.data: = suquery.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 I 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;
    
04.04.2017 / 14:36