0
votes

I have a simple DataSnap TCP/IP based client server application. I created a ClientDataSet on Client Application and filled it some data. Now how can I send my ClientDataSet records to Server so that I can process it and eventually save some data to server.

Edited

So I tried the below code, but the problem is that at server I am getting 1 less record than what I am sending from client

Client Code

var
 cd: TClientDataSet;
begin
  cd:= TClientDataSet.Create(self);
  cd.Data := cdsCustomer.Data;
Memo1.Lines.Add(IntTostr( cd.RecordCount )) ;
 ServerMethods1Client.TestDataSet( CD);

Server Code

function TServerMethods1.TestDataSet(ds: tdataset): string; 
begin     
  try
    DataSetProviderCommon.DataSet := ds;
    if not DataSetProviderCommon.DataSet.eof then
     TempClientDataSet.Open;

    if  TempClientDataSet.RecordCount >0 then      
       Form1.Memo1.Lines.Add( IntTostr( TempClientDataSet.RecordCount) )       
    else
        Form1.Memo1.Lines.Add( ' Not records found' ) ;

    DataSetProviderCommon.DataSet.Close;   
  except on e: Exception do
    Form1.Memo1.Lines.Add('TestDataSet error :' + e.Message )   ;   
  end;
end;   
1

1 Answers

1
votes

You can simply pass the Data property to the server as OleVariant type (likewise you can pass data from server back to the client using OleVariant result type or var/out parameters):

Client Code

begin
  Memo1.Lines.Add( IntTostr( cdsCustomer.RecordCount ) );
  ServerMethods1Client.TestDataSet( cdsCustomer.Data );
end;

Server Code

function TServerMethods1.TestDataSet(ds: OleVariant): string; 
begin     
  try
    TempClientDataSet.Data := ds;

    if TempClientDataSet.RecordCount > 0 then      
      Form1.Memo1.Lines.Add( IntTostr( TempClientDataSet.RecordCount ) )       
    else
      Form1.Memo1.Lines.Add( 'No records found' ) ;

    TempClientDataSet.Close;   
  except on e: Exception do
    Form1.Memo1.Lines.Add( 'TestDataSet error: ' + e.Message );   
  end;
end;