DataSnap is a technology that enables RAD creation of multi-tier web applications. You can use HTML5 Builder to create client-side web applications that interact with DataSnap.
Generate DataSnap Files
Open an existing project. Once open, go to File > New > Other… > HTML5 Builder Projects > PHP Files, select DataSnap REST Client Module and click OK.
On the New DataSnap REST Client Module dialog, fill the properties as needed:
- Set the Protocol to either http (faster) or https (more secure).
- Set the Host and the Port to those used by your DataSnap server.
- You might need to also fill URL Path, Context, User name and Password fields.
Once you are done, click OK. Two files will be added to your project, by default: ClientClassUnit1.php and ClientModuleUnit1.php.
The later, the module, contains a DSRestConnection component, which will be responsible for the connection with the DataSnap server. It also includes a read method, readServerMethods1Client(), which returns an instance of a class, TServerMethods1. This class is defined in the former file, the class one, and contains the methods on the DataSnap server you will be able to call from your web client.
Call DataSnap Methods
Open an script of the project from which you want to call DataSnap server methods. Then go to File > Use Unit…, an in the Use Unit dialog, select ClientModuleUnit1.php and click OK. A line like this will be added to your script, in the proper section of the source code:
Now, wherever you want to call a DataSnap method in you code:
- Include the global variable for the module:
- Call the method from its ServerMethods1Client property:
- HTML5 Builder: DataSnap REST Client Module Tutorial, by Al Mannarino.
- HTML5 Builder: DataSnap REST Client Module for Database Tutorial, by Al Mannarino.
- HTML5 Builder Multi-tier Application Development, by Al Mannarino.
- HTML5 Builder and Delphi DataSnap, by Nirav Kaku.
- Connecting an HTML5 Builder Application to a Delphi or C++ DataSnap Server.