Smart Mobile Studio
  • News
  • Forums
  • Download
  • Store
  • Showcases
    • Featured demos
    • The Smart Contest 2013, Round 1 – Graphics
  • Documentation
    • Get the book
    • System requirements
    • Prerequisites
    • Getting started
      • Introduction
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • Themes and styles
    • Project types
      • Visual project
      • Game project
      • Console project
    • Layout manager
    • Networking
      • TW3HttpRequest
      • TW3JSONP
      • Loading files
  • About

Using DataSnap Connector Importer

Posted on 20.12.2014 by gabr42 Posted in Documentation, News

This tutorial shows how to use DataSnap connector in the Smart Mobile Studio Enterprise.

Server

Firstly, create a DataSnap server. In this example we are using Delphi XE7 but any older version will be OK as long as it can create a REST server.

Start by creating new project. Select DataSnap REST Application from the DataSnap Server branch. It is important to create REST server as Smart doesn’t work with binary data format used in MIDAS-based DataSnap server.

Create DataSnap REST server

Any application type will do, but for simplicity we are using Stand-alone application in this demo.

Select application type

VCL and FireMonkey applications both work fine as DataSnap server is not dependent on the GUI framework.

Select GUI framework

Enter a number of an unused port.

Set port number

Select Mobile Connectors support. This is important as without this feature Smart cannot build its own connector! Keep Sample Methods checked as we’ll be using one of them in the demo.

Add Mobile connectors

Any server method ancestor will do. In this demo we are using a simple TComponent.

Select ancestor class

At the end, provide a path to the project files.

Set location

Save everything, compile, run, and click Start.

Run

Client

Now is the time to create a Smart Mobile Studio client. It could be running on the same computer as the DataSnap server or on a different machine. You just have to make sure that the computer running Smart also has a Delphi Enterprise edition installed. Any Delphi version that supports writing DataSnap REST clients should be OK. RAD Studio XE5 was used when preparing this example.

Start a new project. Visual Components Project will typically be used but for this example we have used a simpler Console Project.

Create Smart project

Save the project. DataSnap connector importer requires that the project is saved.

Select Tools, Import DataSnap connector from the menu.

Import DataSnap connector

DataSnap connector wizard will appear. Enter the URL of the DataSnap service in the first field and a name of the unit to be generated in the second field. Then click Import.

Set import parameters

Importer will create new unit (DSClient.pas in our example), add it to the project and open it in the editor.

Generated unit

Now open the main project unit (Unit1) and add units DSClient and DataSnap to the implementation section.

uses
  DSClient,
  DataSnap;

Add the following code to the PopulateConsole method.

var ds := TServerMethods1_Client.Create(
  TDataSnap.CreateConnection('hermione', 8080, ''));

Console.Writeln(ds.ReverseString('Calling DataSnap from Smart!').result);

The first statement creates a DataSnap client instance. It can be used to execute multiple calls to the same server. You will have to replace computer address and port (first two parameters) with appropriate values (for example, you’ll have to replace ‘hermione’ – the name of the test machine running DataSnap server application –  with ‘localhost’ if you’ll be running the server on the same computer as the client). The third part is the URL path appended to the host:port to create the DataSnap server address.

The second statement calls the ReverseString method on the server and writes out the result.

We can also programmatically generate the URL used for the REST call (without calling it) by calling the ReverseString_URL method.

Writeln(ds.ReverseString_URL('Testing...'));

The picture below shows the built-in browser after both calls are executed. Reversed string is written in the console application window (upper part) while the URL is written in the browser’s console window (lower part). (Why? Because Console.Writeln writes to the application window and Writeln writes to browser’s console.)

Smart client running in browser

We can copy the URL from the browser’s console and paste it in a browser for testing.

Calling DS server from browser

Test project

You can download sample project (both Delphi and Smart parts) from: DataSnap client/server demo

Recompile the Delphi part with Delphi Enterprise. Recompile the Smart part with Smart Mobile Studio Enterprise.

Sample client application expects DataSnap server to be running at localhost:8080. If that is not the case, you’ll have to correct parameters to TDataSnap.CreateConnection call in Unit1.

 

« Writing REST Clients with Smart 2.1.2
Using DataSnap Importer to Work with Datasets »

Pages

  • About
  • Feature Matrix
  • Forums
  • News
  • Release History
  • Download
  • Showcases
    • The Smart Contest 2013, Round 1 – Graphics
  • Store
  • Documentation
    • Creating your own controls
    • Debugging, exceptions and error handling
    • Differences between Delphi and Smart
    • Get the book
    • Getting started
      • Introduction
      • Local storage, session storage and global storage
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • pmSmart Box Model
      • Themes and styles
    • Layout manager
    • Networking
      • Loading files
      • TW3HttpRequest
      • TW3JSONP
    • Prerequisites
    • Real data, talking to sqLite
    • System requirements
    • Project types
      • Visual project
      • Game project
      • Console project

Archives

  • December 2019
  • December 2018
  • November 2018
  • July 2018
  • June 2018
  • February 2018
  • September 2017
  • April 2017
  • November 2016
  • October 2016
  • September 2016
  • April 2016
  • March 2016
  • January 2016
  • October 2015
  • September 2015
  • July 2015
  • April 2015
  • January 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • November 2011
  • October 2011
  • September 2011

Categories

  • Announcements (25)
  • Developers log (119)
  • Documentation (26)
  • News (104)
  • News and articles (16)

WordPress

  • Register
  • Log in
  • WordPress

Subscribe

  • Entries (RSS)
  • Comments (RSS)
© Optimale Systemer AS