This sample shows how to create a DataSnap REST Server in Appmethod C++, expose server methods, and call them from an Android application.
You can find the Appmethod C++ DataSnap Server sample at: http://cc.embarcadero.com/download.aspx?id=28677
The sample shows how to create a DataSnap server in Appmethod C++ and how to expose the server methods to clients. The form contains three TButtons and a TEdit. Two of the buttons (Start and Stop) are used to start and stop the DataSnap server, and the Open Browser button opens a web browser and displays the server methods in order to test them. The TEdit control is used to set the server port.
In this sample, four server methods are implemented. Two of them are InsertCountry and GetCountries. These methods execute some queries against an InterBase database. The InsertCountry method adds a row to the Country table of the database, and the GetCountries method returns the content of the Country table.
Note: The server uses the following credentials:
Note: For more information about how to connect an Android client to the DataSnap server, see the following page: Android applications connected to Appmethod C++ DataSnap server.
How to Use the Sample
- Open the DSCBuilderServer folder from the extracted folder, and open CBuilderDSServer.cbproj.
- Build CBuilderDSServer.cbproj.
- Run the application by selecting Run > Run menu, or by pressing F9.
- Select a proper port and then click the Start button to start the server.
- Select Open Browser and then click the Server Functions link to test the server methods:
- Expand the TServerMethods1 node and then InsertCountry.
- Fill the country(String) and currency(String) fields with proper data.
- Click Execute.
- Expand the TServerMethods1 node and then GetCountries.
- Click Execute.
The files used by this sample are:
The main form that constitutes the user interface for the DataSnap Server.
The server methods that are exposed to clients.
Functions to handle the display of the server methods in the browser.
- TForm1 represents the class for the main form. It contains three TButton controls , a TLabel, and a TEdit. The main form contains the user interface for the server.
- TServerMethods1 represents the class that defines the connection to the database and the four sever methods.
- TWebModule1 is the class that implements methods to display the server methods in the browser.
- A TSQLConnection object describes the connection to the InterBase database.
- To execute the queries against the database, the sample uses a TDBXCommand object.