Copying data from DBXReader to ClientDataSet

Categories:DelphiTags: , ,

If you are using DataSnap 2010/XE for sure use DBXFramework, which I strong recommend for operations where you don’t use Data Aware components or bi-directional datasets.

There are situations where you will need to copy data from DBXReader to TClientDataSet or TParams, for this kind of situation Delphi has the unit DBXDBReaders.pas, which contain some classes that allow this kind of operation.

The TDBXDataSetReader class contain the method CopyReaderToClientDataSet, on this method you pass the DBXReader that contain the data to copy to the ClientDataSet, which is the second parameter, the follow code demonstrate that:

var
  Reader: TDBXReader;
  DepClient: TDepartmentClient;
begin
  DepClient := TDepartmentClient.Create(DMClientContainer.MyDSServer.DBXConnection, False);

  try
    Reader := DepClient.GetDepartmentsOrderBy;

    try
      if Assigned(Reader) then
      begin
        TDBXDataSetReader.CopyReaderToClientDataSet(Reader, DMClientContainer.CDSCopy);
      end;
    finally
      FreeAndNil(Reader);
    end;

  finally
    DepClient.Free;
  end;

The ClientDataSet CDSCopy already exist and is part of the DataModule DMClientContainer. if you don’t have a ClientDataSet created, use the method TDBXDataSetReader.ToClientDataSet, it wil return a new ClientDataSet.

My DataSnap 2010 samples was updated and you can download from here

3 Responses to Copying data from DBXReader to ClientDataSet

  1. Reply Samuel says:

    A função TDBXDataSetReader.CopyReaderToClientDataSet
    acaba truncando os campos no cliente dataset! Como Resolver?

    • Reply Andreano Lanusse says:

      Oi Samuel,

      Vai na unit DBXDBReaders na procedure CopyValueTypeProperties, localize a linha onde está
      if ValueType.DataType = TDBXDataTypes.WideStringType then

      e mude para

      if ValueType.DataType in [TDBXDataTypes.WideStringType, TDBXDataTypes.AnsiStringType] then

      Isso irá resolver o problema de truncar.

  2. Reply Copying data from ClientDataSet to DBXReader | Andreano Lanusse Blog | Technology and Software Development says:

    […] probably already read my post Copying data from DBXReader to ClientDataSet, now is time to learn how copy data from ClientDataSet to DBXReader using Delphi or […]

Leave a Reply

Your email address will not be published. Required fields are marked *