How to return a DataSet from a DataSnap Server

I Have coded trivial a DataSnap server  and client with Embarcadero XE3  C++ builder which works and returns a double when a Sum() method is called.
I now wish to code the server to return a Dataset from a Table which is accessible at the server end and have the client receive the DataSet for local processing.
how do I do this ? I can't code a method at the server such as :

TDataSet  TMyClass::ATable(void)
{
      return *DataModule1->SQLTable1;
}

so I am guessing that there are DataSnap components that need to be used at the server end and the Client end ?
I attach a screen shot of the server components that I am using.

DataSnap server Main form
LVL 2
Roger AlcindorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roger AlcindorAuthor Commented:
I have found some code (shown below) for the server that would appear to provide an example of the functionality that I need.
What code would I need to receive the Dataset at the client end (Windows 32 App) ?

TDBXReader* TServerMethods1::GetCountries() {

      TDBXCommand *comm;

      try {
            DbConn->Open();
            comm = DbConn->DBXConnection->CreateCommand();
            comm->CommandType = TDBXCommandTypes_DbxSQL;
            comm->Text = "Select * from Country";

            if (!comm->IsPrepared) {
                  comm->Prepare();
            }
            return comm->ExecuteQuery();
      }
      catch (Exception* e) {
            return NULL;

      }

}
0
sarabandeCommented:
i don't know much about Embarcadero XE3 but, generally, you would send the data set as a byte array to the client. if the byte array is big - say greater 1k - you would send fixed sized 512 bytes packets until the data was fully sent.

at the client side you probably would wait for the data set in a separate thread what makes your program still responsive. so the general design would be

client:   connects to server
server: accepts client
client:   sends request to server
server: receives request
             checks request and returns TRUE if valid, FALSE otherwise.
client:  error on FALSE
             starts thread and passes connection handle
             returns to user interface
client
thread: waits for server response with timeout
server:  query for data set
              on success sends data of data set as a byte array to client
thread: receive dataset as byte array.
              stores bytearray into a shared dataset
              message to ui thread "data received"
              exits thread.
client:   receive message in a timer handler
              show (and/or store) data set

Sara
0
Roger AlcindorAuthor Commented:
Hello Sara,
I have solved the issue with help from another. The solution is given at
 http://www.experts-exchange.com/Programming/Languages/CPP/Q_28670748.html#a40769868
Thanks for your comments in any case.

Roger
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

sarabandeCommented:
thanks for your feedback.

i looked at the solution and it looks straight-forward. however, it seems to be a sychronous call to server. if so, the foreground would "freeze" in case of a lengthy query. if that is a problem, you may consider a multi-threaded solution where you keep the user-interface working while waiting for the data set to be returned in a thread. that is not very difficult. you simply would create a new thread in the OnButtonClicked handler and would let do the thread call the server and wait for response while the OnButtonClicked would return.

Sara
0
Roger AlcindorAuthor Commented:
I will bear that in mind for the future. In this application the query is not a lengthy one and the server is only accessed by the client when the application starts. I anticipate that the foreground freezing would not be an issue as the dataset being returned is only about 30 records.

Roger
0
Roger AlcindorAuthor Commented:
The issue was solved on another question that I submitted and points were awarded there, see
 http://www.experts-exchange.com/Programming/Languages/CPP/Q_28670748.html#a40769868
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.