Copying data from DBXReader to ClientDataSet

Let's share the knowledge with your friends

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


Let's share the knowledge with your friends
3 replies
    • Andreano Lanusse
      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.

      Reply

Trackbacks & Pingbacks

  1. […] 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

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.