Skip to content

Delphi Labs: DataSnap code samples updated to XE3

It seems that it is my very first post in the New Year 2013, so I wish You all the best and great time writing all kinds of programs. I’m sure it is going to be a great year for Delphi and Marco is predicting it as well, especially that next month Delphi is going to become adult!

Two years ago I have put together a serie of Delphi DataSnap tutorials called "Delphi Labs" and many people found it useful, so I thought that it is a high time to at least update code samples for every tutorial so they compile with the latest version of Delphi which is right now XE3.

Below is the list of updated Delphi Labs DataSnap episodes, with information about changes made to the original XE code samples and the actual link to CodeCentral. In order to keep things simple I have reuploaded every demo source code to the same CodeCentral URL, so links to code remain the same. Inside every zip file there are two top level folders: "XE" for original files and "XE3" for updated source code.

You can find the master page with all DelphiLabs DataSnap XE tutorials at www.embarcadero.com/rad-in-action/delphi-labs

Episode 01: Simple Calculator Servicevideo, whitepaper, source code

Both server and client projects compile fine, however if you run the server or the client, you would get "EIPAbstractError" exception with "No peer with the interface with guid [...] has been registered".

Where is this error coming from? In the example we are using DataSnap TCP/IP connectivity, which is internally implemented using Indy framework. The Indy implementation has changed between XE and XE3 versions, so there are little changes needed. On the server it is necessary to add "IPPeerServer" to the interface "uses" clause in the "ServerContainerUnit1" and on client we need to add "IPPeerClient" to the interface "uses" clause in the "ClientModuleUnit1". In fact the IDE can add these entries automatically. Just put the cursor somewhere in the "uses" clause of these two files and when you press "Enter" correct entries will be added for You! Cool:-)

I have also added a project group file "SimpleCalcGrp" and updated forms’ captions to "XE3".

Episode 02: Multitier Database Application - video, whitepaper, source code

Two changes to source code here. One is the same as in Episode 01 and involves adding missing "IPPeerServer" and "IPPeerClient" units to "uses" clauses in the server and in the client project. The second change introduced was changing the database connection name in the TSQLConnection component on the server from "IBEMPLOYEE" to "EMPLOYEE". Delphi XE3 comes with a preconfigured "EMPLOYEE" connection to a sample InterBase database, so you can just open the project group, build all, run server and then run client and it should work "as is". A true multitier database application!

Episode 03: Server Methods Lifecyclevideo 1 and video 2whitepapersource code

The third tutorial explores the different server methods instances lifecycle options. Understanding lifecycle of server side objects is critical to DataSnap architecture. I have just added missing "IPPeerServer" and "IPPeerClient" entries and updated forms’ captions and sizes. Below is a screenshot from a running demo with one server app and two clients invoking server methods on server objects with different lifecycle options set.

Episode 04: Testing DataSnap Server in Data Explorer - video, whitepaper, source code

Data Explorer has been completely redesigned in Delphi XE3 and is now much more powerful. The demo contains just a server project, which listens to clients on TCP/IP port 211 and HTTP port 8080.

The only changes to original XE source code was to add "IPPeerServer" unit and updating form caption.

Episode 05: Authentication and Authorization - video 1 and video 2, whitepaper, source code

Standard changes. Adding "IPPeerServer" and "IPPeerClient" units plus form captions updated.

Episode 06: Transport Filters - video, whitepaper, source code

Beyond standard changes including adding "IPPeerServer" and "IPPeerClient" units and modifying forms’ captions, I have also added one line to the client "OnClick" event handler to make sure that the connection is open before calling a server method.

with SQLConnection1 do if not Connected then Open;

Transport filters is a very elegant feature!

Episode 07: REST Web Application - video, whitepaper, source code

The "REST Web Application" is a walk through different parts of a standard Delphi REST app generated with the wizard with default options. In this tutorial the "Add" server method is implemented and dynamically generated JavaScript proxies are shown.

Between XE and XE3 there were some refactorings performed. One of them was moving "TDSSessionManager" class from "DSService" unit to "DataSnap.DSSession". As the consequence this is a change that has to be done to compile the XE version of DataSnap REST server application in XE3: to change the "uses" clause of the main form unit and replace "DSService" with "DataSnap.DSSession". That is the only change except for updating main form’s caption to "XE3".

Episode 08 (part 1): WebBroker jQuery Mobile "Boilerplate" - video 1 and video 2, whitepaper, source code

Next two episodes in the serie has been inspired by the presentation that I had to prepare for students in the University College of London (UCL). I wanted to do something new and interesting. This tutorial is not exactly DataSnap, it is more generic. DataSnap servers can be implemented as either standalone executables or hosted in a web server. "WebBroker" is the underlying technology of all web server project types in Delphi: "DataSnap REST Application", "DataSnap WebBroker Application", "SOAP Server Application" or just a custom HTTP "Web Server Application".

Two years ago jQuery Mobile was not as widely known as it is today, but it definitely had its already high "coolness" factor. In this demo I have combined "jQuery Mobile Boilerplate" with a generic Delphi WebBroker application as a starting point to the next tutorial.

The Delphi XE version of the demo compiles and works with no modifications in XE3, however two years ago jQueryMobile framework was still in beta and today the latest stable version is "1.2.0 Final". I have updated the demo project to reference the latest jQuery 1.8.2 and jQuery Mobile 1.2.0.

Episode 08 (part 2): jQuery Mobile Web Frontend - video 1, video 2, video 3, whitepaper, source code

This is logically the second part of "WebBroker jQueryMobile Boilerplate" demo. Now that we know how to setup a generic Delphi WebBroker HTTP server application to serve jQuery Mobile markup, we can go one step further and display data from a database instead of a static content.

This episode demonstrates how generate data-driven jQueryMobile web pages generating HTML markup dynamically in Delphi code.

The demo source code contains a project group with two projects. The first project is a DataSnap standalone server ("DataServerApp") with a database connection and architecture very similar to the server from the "Episode 2: Multitier Database Application". The second project acts as a client to it and is an extended version of the jQuery Mobile Boilerplate project from the previous episode.

In the the data server project it was necessary to add "IPPeerServer" unit to the "uses" clause of the "ServerContainerUnit2" file and also to change the "ConnectionName" of the SQL connection component to "EMPLOYEE" (the same changes as in Episode 2).

The changes to the client webbroker project ("jQueryMobileApp") involved updating the reference to jQueryMobile version used in the same way as in the "boilerplate" episode previously.

I have also updated the "About" page markup embedded in Delphi code to display up-to-date information about Delphi, InterBase and jQueryMobile versions used.

The demo app has been updated and reuploaded to Amazon EC2 demo instance. Check it out yourself on your mobile device web browser at http://79.125.25.31:8080

This demo shows how to generate jQuery read-only markup. If you are interested how to use DataSnap REST and jQuery Mobile for interactive web pages, check out my later blog post here.

Episode 09: DataSnap Server implemented as Windows Service - video, whitepaper, source code

The only change needed to update this demo was a standard addition of "IPPeerServer" unit to the server container unit. The project compiles fine and installs and run with no problems under Windows 8.

Episode 10: Passing "Plain Old Delphi Objects" - video, whitepaper, source code

Standard changes only: added "IPPeerServer" and "IPPeerClient" units, created a project group for convinience and also updated form captions.

Episode 11: Callbacks - video 1, video 2, video 3, whitepaper, source code

This is the last episode from the original DelphiLabs DataSnap XE serie and it only touches on one of the most powerful features of DataSnap - callbacks.

In the server project I have only changed the caption of the form and added "IPPeerServer" in a standard way.

The client project is slightly more involving. If you put a cursor inside the "uses" clause of the "FormClientUnit" you will see that not only "IPPeerClient" is added, but also "IPPeerServer". That is OK. In this scenario the server project acts only as a bridge and "clients" are both sending and receiving messages, so they are acting as both clients and servers. It is also necessary to add "DataSnap.DSSession" unit to the "uses" clause, because "TDSTunnelSession" class that is used in code has been moved there. The last change was to add the code to open "SQLConnection1" in the form’s OnCreate event.

When I was reviewing all these episodes - I have realized that it was not only a lot of work, but also great fun to explore this super elegant technology, so…

Delphi Labs will return!

{ 16 } Comments

  1. shuhin Ashayeri | January 10, 2013 at 8:07 pm | Permalink

    Thanx a lot (^_^)

  2. Alan Taylor | January 10, 2013 at 9:58 pm | Permalink

    Excellent,

    Now have someone convert the lot to C++ Builder. Check that it works, check that it is thread safe and doesn’t leak. Then your done.

  3. Mark Ellen | January 10, 2013 at 11:26 pm | Permalink

    Thank you for clarifying the changes re: IPPeerServer/Client, IndyPeerImpl stays does it?

    Have you tried enabling the RSA,PC1,ZLIB Filters on the Server and ZLIB on the Client?

    Using \Documents\RAD Studio\10.0\Samples\Delphi\DataSnap\Authorization:
    AuthServerProject and SimpleDelphiClient

    I have and I get an error:
    Exception: TDBXError, error:0D0680A8:asn1 encoding routines:func(104):reason(168)

    I’ve tried various versions ( 9.x.x and 1.x.x ) of OpenSSL ssleay32 and libleay32 including the versions shipped in the bin/subversion directory and from http://indy.fulgan.com/SSL/ but no success.

  4. Vsevolod Leonov | January 11, 2013 at 8:27 am | Permalink

    Great! Thank for the job.

  5. cheap diablo 3 gold | January 14, 2013 at 6:43 am | Permalink

    I have mastered some essential things through your site post. One other stuff I would like to say is that there are numerous games out there designed specifically for preschool age young children. They involve pattern acknowledgement, colors, wildlife, and shapes.

  6. Curt | January 14, 2013 at 10:45 am | Permalink

    Aw, this was a very good post. Finding the time and actual effort to make a really good article… but what can I say… I put things off a
    whole lot and never manage to get anything done.

  7. Top Web Hosting | January 14, 2013 at 5:14 pm | Permalink

    Magnificent site. Lots of helpful info here. I’m sending it to several pals ans additionally sharing in delicious. And of course, thank you to your effort!

  8. james twomey | January 15, 2013 at 5:35 pm | Permalink

    great job, I used xe3 and love it but have just started on firemonkey which is really fantastic. There isnt a webbrowser componant for firemonkey can you give me any guidelines on how to write or get one
    Thanks and keep up the great updates they save so much time

  9. http://www. | January 16, 2013 at 6:28 am | Permalink

    A friend referred me to this site. Thnx for the information.

  10. Hosein Pakdel | January 30, 2013 at 9:25 am | Permalink

    Excellent!Thanks a lot .

  11. replica rolex | February 3, 2013 at 6:14 am | Permalink

    This is the perfect website for anybody who
    really wants to understand this topic. You
    realize so much its almost hard to argue with you (not
    that I actually would want to…HaHa). You certainly put a fresh spin
    on a topic that has been written about for ages. Wonderful
    stuff, just wonderful!

  12. Alexandre Xavier | March 1, 2013 at 11:33 pm | Permalink

    Mr. Pawel Glowacki,

    In this Delphi Labs episode "Building the Server as Windows Service" for Delphi XE3, is possible to include a form that is visible on the server? (Win7 or Win8)

    For example: Showing Service status (running, stopped or suspended) or if the database is connected.

  13. Carlos Niebla | March 13, 2013 at 2:37 am | Permalink

    Hi Pawel,

    Your Delphi Labs - DataSnap work has helped me a lot with a client-server application that I need to convert to DataSnap but with the new addition of FireDAC I would prefer to use FireDAC instead of DBX.

    How about some samples of a DataSnap application using FireDAC? I think that a lot of people would appreciate it.

    Regards,
    Carlos Niebla.

  14. Allen | May 1, 2013 at 9:31 pm | Permalink

    Mark Ellen, ( or anyone else)

    did you ever resolve the rsa/pc1 error? I’m having the same issue. Would be nice to know how to resolve it. It works correctly on XE2 and XE4. In XE3 the server/client seem have issues exchanging the RSA key.

    Thanks

  15. Allen | May 2, 2013 at 7:29 pm | Permalink

    After much pain and debugging (and installing XE4 and and seeing how it worked) I have determined that know one is using XE3 datasnap with RSA/PC1 filters because it doesn’t work. There is a flaw in the functions Getpublickey and SetConfederatePublicKey in data.DBXOpenSSL. The key that is encoded and returned to the client is invalid. You have to replace the LWrapper (TPtrWrapper) with a PByte (like it is in XE4) and it will correctly.

  16. Jofan | May 22, 2013 at 4:23 pm | Permalink

    Hi Pawel, I’m using Delphi XE3 ent, Datasnap rest server , my servermethods return a DBXreader, how can i do that with FireDAC?
    thanks

Post a Comment

Your email is never published nor shared. Required fields are marked *

Bad Behavior has blocked 2 access attempts in the last 7 days.

Close