DataSnap

From HTML5 Builder
Jump to: navigation, search

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.

Workflow

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).
  • Choose a Programming Language for the module. It can be either PHP or JavaScript. If you choose PHP, the connection will be setup with RPCL components; if you can it to be generated with pure PHP code, just check the Generate pure PHP code option.
  • 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: require_once("ClientModuleUnit1.php");.

Now, wherever you want to call a DataSnap method in you code:

  1. Include the global variable for the module: global $ClientModuleDataModule1;
  2. Call the method from its ServerMethods1Client property: $ClientModuleDataModule1->ServerMethods1Client->methodName()

Help Resources

Tutorials

Video Tutorials

Documentation