Generating customer loyalty cards, event tickets, coupons, boarding passes for the smartphone with TMS PassKit

Monday, June 19, 2017

With iOS 9 and iPhone 6, Apple introduced the digital wallet on your smartphone. It is a system that holds passes to redeem rewards, get movie tickets, use discount coupons, get boarding passes for transport, offer prepaid cards etc.. An introduction to using the iPhone Wallet on an iPhone or iPod touch can be found here.
The pass for the iPhone or iPod is nothing more than a digitally signed file that can be distributed via a download, attached to an email, shared via AirDrop, ...

To facilitate generating such wallet PassKit files, we have released a new product TMS PassKit. TMS PassKit handles all the complexities of the signing of the files and has support for all PassKit type passes: coupons, tickets, store cards, traffic pass, generic pass ... It makes generating a wallet file as easy as setting up properties and call TMSPassKitBuilder.Generate() to generate the file. This component can make is really easy to automatically send out a wallet file with a loyalty card to all your customers, send tickets for inviting people to an event, create payment cards for employees and more...

This is an example wallet file that was created with TMS PassKit for a sample event: TMS training day 2017:

PassKit frontPassKit back

As you can see the wallet file can have both a front and back side. The appearance of the front can be customized via various settings, images can be added and as can be seen here, optionally, it can include a barcode in different formats.
The back of the card can contain additional fields and when these fields include an email, phone number, URL, date, ... this can be used to link to the mail app, calendar app, phone, ...

Wallet files have more important features, such as location sensitivity, beacon sensitivity, NFC coupling. With these features, supported from TMS PassKit, it is possible to make a pass only active in the neighbourhood of a specific location or beacon and do a transaction via NFC.
Finally, a wallet pass file also has built-in support for localization. Content for multiple languages for the wallet pass can be setup via TMS PassKit. Users with their smartphone configured in a specific language will see the wallet pass in their language of choice.

We are pleased that from today, TMS PassKit is released and available as standalone product but it is also part of the TMS VCL Subscription and TMS ALL-ACCESS. So, customers with an active subscription to either of these subscriptions have received this product for free today.
Head over to the TMS PassKit product page and discover the new possibilities you can add to your Delphi applications for creating wallet files for your users, customers, employees, network, friends, ..

Bruno Fierens


This blog post has received 5 comments. Add a comment.

Function approximation with TMS Analytics and Physics numerical tools

The problem of data approximation (curve fitting, surface fitting) arises from many areas: economics, physics, informatics and many others. There are many libraries, realizing numerical tools for using the approximation in software applications. The TMS Analytics and Physics pack contains the approximation numerical tool which has one unique feature – it is totally integrated with symbolic calculus. Using symbolic expressions with the numerical approximation gives the developer many advantages.

Let us consider a simple case of using the approximation tool for curve fitting (one-dimensional approximation). For this case we have a set of points Pi=(xi,yi), i=1..N. From the programming point of view we just have two arrays of real values, say X and Y. The approximation problem is to build a function y=f(x) which is close to the set of points. The most popular approach of the approximation is the linear least squares ( With TMS approximation tool the problem can be solved in five lines of code:

  approximator: TLinearApproximator;
  basis: TLinearBasis;
  variables: TArray;
  functions: TArray;
  cValues: TArray;
  variables:= TArray.Create('x'); // 1
  functions:= TArray.Create('e^x', 'sin(x)', 'e^-x', 'x^2', '3^x',   'sinh(2*x)'); // 2
  basis:= TLinearScalarBasis.Create(variables, 'C', nil, functions); // 3
  approximator:= TLinearLeastSquares.Create; // 4
  cValues:= approximator.Approximate(basis, X, Y); // 5
  // Using the basis with optimal coefficient values.
Line 1: Create the array of variable names, as this is 1D approximation, there is one variable name ‘x’ in the array.
Line 2: Create the array of approximation functions (basis functions). The functions only depend on the ‘x’ variable. The type and the number of the basis functions can be arbitrary.
Line 3: Create the basis instance with the specified arguments. The ‘C’ argument specifies the name of approximation coefficients. The ‘nil’ argument tells that there is no parameters in the functions.
Line 4: Create the appropriate approximator instance. For the linear least squares approximation it is ‘TLinearLeastSquares’;
Line 5: Calculate the approximation coefficients for the specified basis and arrays of points ‘X’ and ‘Y’.

After the optimal coefficients found, we can evaluate the basis in any point and make other analytical manipulations. As example, here is the plotted approximation function with the original data points on the picture.

The main feature of the TMS numerical tools is they are totally integrated with the symbolic calculus. It brings the following advantages to the developer:
- Minimal code writing, because there is no need to write special classes for the function method references (delegates) as in other numerical libraries.
- Convenient data representation for the developer and user as math expressions, not as programming code.
- Easily using the user input data (string data) for manipulations in programming code.
- Almost unlimited choice of math expressions for manipulations, including special functions.
- Easily transfer input data and the output results via network as strings, easily storing and serializing the data.

The result of the approximation can be easily used with other numerical tools. For example, we can analyze the approximation function for the roots and special points – extremums. The code for the analysis is the following:
  f: string;
  sf1D: TSymbolicFunction1D;
  opt: TSolverOptions;
  points: TArray;
  f:= basis.Evaluate(cValues); // 1 
  sf1D:= TSymbolicFunction1D.Create('x', f); // 2 
  opt:= TSolverOptions.Create(true);  // 3
  points:= TFunctionAnalyser.Analyse(sf1D, TNewton, opt, -2, 3, 10); // 4 
  // Using the points array.

Line 1: Make the function expression with optimal coefficient values.
Line 2: Create the symbolic function instance for the analysis.
Line 3: Create default options for the nonlinear solver (which used for the function analysis).
Line 4: Finding all function's special points on the interval [-2..3]. The Newton’s method used for finding roots and extremums of the function which specified with the second argument.

The result of the analysis – function’s roots and extremums, presented on the picture below.

The TMS Analytics and Physics pack includes the library with 5 ready-to-use numerical tools totally integrated with analytical features, such as symbolic derivatives. The version can be downloaded from the product page. There is the source code example for all numerical tools with the new version download.

Bruno Fierens


This blog post has received 2 comments. Add a comment.

TMS XData REST Server on Linux - Step by Step - Part 5

Thursday, May 25, 2017

This is part 5 of the tutorial on how to create TMS XData and TMS Sparkle servers on Linux. On Part 4, we have added Sparkle to our Apache module, preparing it to receive any modules we want to add. And in this final part we will add the TMS XData module to it.

Here is video for part 5: Adding the TMS XData module to Apache.

Now that we can add any Sparkle module we want, develop our XData server should be nothing different from when we use Windows. You can find more detailed information about it in other resources (blog posts, our TMS XData documentation, etc.). This tutorial will just cover the basics and deal with some final Linux specific things, like SQLite database permissions.

1. Create a new Aurelius connection for SQLite database

Go to Delphi menu item "File, New, Other...", then "Delphi Projects, TMS Business, TMS Aurelius DB Connection" to open the wizard. Choose "SQLite" for both driver and SQL dialect, and then confirm to create the new connection. Unit name created will be called "ConnectionModule".

2. Add XData Module to Sparkle server

Going back to WebModule1 unit, add the following units to the uses clause:

   {...}, XData.Server.Module, ConnectionModule, Aurelius.Engine.DatabaseManager;

Now remove the Sparkle anonymous module we have added just for testing in previous part 4 of this tutorial, and add the new XData module. Also, let's do a call to TDatabaseManager.Update so our tables and columns are created in the database if needed. The final code of initialization/finalization part of our unit should be like this:

  Server := TWebBrokerServer.Create;
    'http://ubuntu/tms', TSQLiteSQLiteConnection.CreateConnection

3. Define SQLite database location

The two steps above should be enough to get our XData server up and running (yep, only those). But our server connects to a database, and we have chosen to use SQLite. We must then define the location of our SQLite database, and specifically on Linux, we should create and set permissions on it so Apache module can read and write to the database.

Let's go back to the ConnectionModule unit created by the wizard, and change the location of SQLite database by changing the parameter in the TSQLiteSQLiteConnection.CreateConnection function:

class function TSQLiteSQLiteConnection.CreateConnection: IDBConnection;
  Result := TSQLiteNativeConnectionAdapter.Create('/home/user/xdata/xdata.db');

In our example, the SQLite database will be the xdata/xdata.db file in our home folder. You might need to change that location a little bit if you have a different user name on Linux.

4. Create SQLite database on Linux and give proper permissions

Now let's go back to Linux terminal and create the database. Make sure you are in your home directory (you can use "cd" command for that):

mkdir xdata
touch xdata/xdata.db

Now, we need to give Apache access to our database. On Ubuntu, Apache module runs under "www-data" group. This will work here if you are following this tutorial from the very beginning, but it can vary depending on the Linux flavor you are using or other Apache settings. In our case, we will change the group of our xdata folder and all its content to "www-data":

sudo chgrp www-data xdata -R

5. Install SQLite library

Our XData module in Apache will use SQLite to access the database. We must then install SQLite libraries for it to do that. If we were using any other database, like MySQL, PostgreSQL, etc., we would might need to install proper client libraries for them as well. Use the following command to install SQLite library:

sudo apt-get install libsqlite3-dev

6. Rebuild, deploy and restart Apache

All is done. We just have to rebuild our Apache module, deploy it again on Linux, and restart Apache on Linux like we did before in previous parts of this tutorial:

sudo apache2ctl stop
sudo apache2ctl start

And our XData server should be running at root address "http://ubuntu/tms"!

This is the end of this tutorial, I hope it was useful for you. From now on, developing further the XData server is no different than developing for Windows. The video above shows more steps further, like creating an entity in the server and doing some CRUD operations on it.

And of course, for further information on TMS XData, please refer to the XData web page or XData documentation.

Wagner R. Landgraf


This blog post has received 2 comments. Add a comment.

TMS XData REST Server on Linux - Step by Step - Part 4

Wednesday, May 24, 2017

This is part 4 of the tutorial on how to create TMS XData and TMS Sparkle servers on Linux. On Part 3, we have created and deployed our first Apache Module using WebBroker. Now we're going to add TMS Sparkle to it.

Here is video for part 4: Adding TMS Sparkle and using Sparkle modules in the Apache module.

Basically, what we need to do is "wrap" the WebBroker request/response objects into a Sparkle request/response objects. So any Sparkle module can process the requests and provide responses. This part is also described in the documentation, in this page:

1. In WebModuleUnit1 unit, add the units Sparkle.WebBroker.Server and Sparkle.WebBroker.Adapter to the uses clause:

uses {...},
   // just for the anonymous module example
  Sparkle.HttpServer.Module, Sparkle.HttpServer.Context;

2. Declare and create a global TWebBrokerServer instance:

Add a global variable declaration in the unit:

  Server: TWebBrokerServer;

And then create it in initialization:

  Server := TWebBrokerServer.Create;

3. Replace the WebModule1DefaultHandlerAction event handler with the code below to dispatch the requests:

procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
  Adapter: IWebBrokerAdapter;
  Adapter := TWebBrokerAdapter.Create(Request, Response);

And this should be enough to have TMS Sparkle "plugged" into the Apache module. From now on, you can code just like you do on Windows: create Sparkle modules (like XData), and add them to the server Dispatcher. As a quick example, you could add the following anonymous module to test:
  Server := TWebBrokerServer.Create;
  // add modules you want to use. This example assumes a simple Sparkle module,
  // but you can add your XData, RemoteDB or any other Sparkle module
    procedure(const C: THttpServerContext)
      C.Response.StatusCode := 200;
      C.Response.ContentType := 'text/plain'';
      C.Response.Close(TEncoding.UTF8.GetBytes('Hello from Sparkle!'));

Now you can rebuild the module and deploy to Linux. If you now go to Linux and restart Apache:

sudo apache2ctl stop
sudo apache2ctl start

And refresh the URL in your browser:


You should see a response "Hello from Sparkle!"

In the next part (the final one) we will add the XData module to our Apache module.

Wagner R. Landgraf


This blog post has not received any comments yet. Add a comment.

TMS XData REST Server on Linux - Step by Step - Part 3

Tuesday, May 23, 2017

This is part 3 of the tutorial on how to create TMS XData and TMS Sparkle servers on Linux. On Part 2, we have installed PAServer and launched our first "Hello, World" console application on Linux.

Here is video for part 3: Create and deploy an Apache module to Linux.

We will use WebBroker to create an empty Apache module. But first we need to install Apache on Linux.

1. Install Apache on Linux

On Linux terminal, use the following command to install Apache:

sudo apt-get install apache2

This should be enough to get Apache up and running. You can open your browser on Windows and just try to open the root page (let's consider our host name is "ubuntu" from now on):


And you should get a page from server telling you that Apache is running.

2. Create WebBroker Apache module in Delphi

Going back to Delphi, use menu option "File, New, Open...", then choose "Delphi Projects, WebBroker, Web Server Application".

Check "Linux" option, Next, and then select "Apache dynamic link module". When choosing the module name, type "xdata_module". Of course you can use any name you want, but we will use this name for further configuration in this tutorial. Finish the wizard and you will have the module created.

3. Build and deploy Apache module to Linux

Now build your Apache module (make sure to first select Linux64 platform in Project Manager, otherwise you would be building the module for Win32), and then click "Project, Deploy" menu option to deploy it to Linux. If you still have your PAServer running on Linux, it should send the module file to Linux.

The deployed file location should be something like this:


I might be slightly different in your Linux computer, because you might have used a different user name for Linux user, and a different user name/profile in your Windows machine (the "User-Ubuntu" part). You can simply use WinSCP from Windows to browse your Linux files and discover where is the .so file deployed by PAServer. You should find it by navigating from the PAServer folder created in your home directory.

4. Create Apache configuration files

We must now configure Apache to use our new module. On Linux terminal, go to Apache module configuration folder:

cd /etc/apache2/mods-available

Create two new configuration files:

sudo touch xdata.conf
sudo touch xdata.load

Edit the first file to load module (we will use Nano editor here, if you don't have it installed in your Linux, you can use command "sudo apt-get install nano"):

sudo nano xdata.load

Use the following content for xdata.load file. Here we must use the location where our .so module file was deployed, as we saw in step 3.

LoadModule xdata_module /home/user/PAServer/scratch-dir/User-Ubuntu/mod_xdata/

Press Ctrl+X to save and exit from nano editor, and then let's edit xdata.conf file:

sudo nano xdata.conf

This should be the content of this file:

<Location /tms>
    SetHandler libmod_xdata-handler

Save that file as well, and Apache configuration is finished.

5. Enable Apache module

The configuration files we created are just a module that is "available". We should now enable the module using the following command:

sudo a2enmod xdata

6. Restart Apache

Now we should stop and restart Apache service. Use the following commands for that (we will use such commands very often further in next parts of this tutorial):

sudo apache2ctl stop
sudo apache2ctl start

7. Test Apache module

Now we can go back to Windows, use our browser and go to the following url (remember to change "ubuntu" to the hostname or IP address of your Linux machine, if it's different):


And the browser should display "Web Server Application" as result.

In the next part we will learn how to add TMS Sparkle to the Apache module.

Wagner R. Landgraf


This blog post has not received any comments yet. Add a comment.

Previous  |  Next  |  Index