DataSnap Mobile Connectors in RAD Studio XE2

Android, Delphi XE2, Events, Programming, RAD Studio XE2, Uncategorized 1 Comment »

WARNING! I’ve been authorized by EMBARCADERO to write about RAD Studio XE2.

RAD Studio XE2 is full of nice and exciting features. One of the most interesting IMHO is the DataSnap extension called “Mobile Connectors”.

In the past, I’ve talked about connecting and using your datasnap REST service with Android, creating ad-hoc json messages and manually parsing the returned json messages. With RAD Studio XE2 this is no longer needed. If you have a DataSnap REST service, you can automatically generate the proxy connector for the major mobile platforms. Yes, just like you have been doing with Delphi or C++ since Delphi 2010.

DataSnap XE2 version supports 4 mobile platforms:

  • Android (Using Java)
  • BlackBerry (Using Java)
  • Windows Phone (Using C#)
  • iOS 4.2 (Using ObjectiveC)

If you want to enable your DataSnap server for the Mobile Connectors you have to explicitely check the feature in the “New DataSnap Server” wizard.

The generated proxies support all the standard Delphi types and maps them to the native target language. Some of the most used Delphi types (e.g. TStream, TDBXReader and so on) have been rewritten in the target language to allows a greater compatibility and a simpler programming interface. The functionalities of the various Delphi classes are not-one-to-one with the Delphi version, but  similar.

From a remote (or local) machine you can download the generated proxy and all the required files using a tool called “Win32ProxyDownloader.exe” which is in the bin folder of your RAD Studio installation. In my FieldTest version, this tool called without parameters, shows its help.

As usual you should have the RAD Studio bin folder in your PATH environment variable, so you can change your current directory to where you want the proxy and write this command in a commandprompt window:

  1. Win32ProxyDownloader -language java_android -host localhost:8080

The proxy and all the needed files are ready in the current directory.

Mat DeLong wrote a very nice Eclipse plugin to use the proxy downloader directly from Android or BlackBerry development environment. You can find this plugin here.

You know that Android is my preferred mobile platform, don’t you?

So, let’s go with an Android example.

To use the generated java proxy, in an Android client application I can write something like this:

//Create the connection
  1. connection = new DSRESTConnection();
  2. connection.setHost("10.0.0.2");
  3. connection.setPort(8080);
  4. connection.setProtocol("http");
  5. //Create the proxy
  6. proxy = new DSProxy.TServerMethods1(connection);
  7. //Use a simple remote method
  8. int sum = proxy.Sum(1,4));
  9. //Use a complex remote method
  10. TStream inStream = null;
  11. TStream outStream = null;
  12. String s = "abc";
  13. inStream = new TStream(s.getBytes());
  14. outStream = proxy.DoSomethigWithATStream(inStream, sum, "Hello DataSnap Mobile Connectors");
  15. //here I can use the java TStream type

All the custom Delphi types (e.g. TPerson) are mapped on the target platform as TJSONObject. All the TJSONValue hierarchy has been ported, with a very similar interface, to the target platform as a wrapper of the native JSON classes.

So, you can write code as the following (Java on Android):

TJSONObject jobj = new TJSONObject();
  1. jobj.addPairs("firstname", "Daniele");
  2. jobj.addPairs("lastname", "Teti");
  3. jobj.addPairs("age", 31);
  4. jobj.addPairs(new TJSONPair("nickname", new TJSONString("Spiderman")));
  5. if (jobj.has("firstname"))
  6.   doSomethingWithFirstName(jobj.getString("firstname"));
  7. doSomethingWithAge(jobj.getDouble("age").intValue());

All the proxies work in a similar way except for the Windows Phone one. Indeed, the WP proxy is asynchronous because Microsoft does not allow a sinchronous http request in the main thread. All the proxies are thread safe.

The proxies are generated on the fly by a set of specialized writers. The TDSProxyGenerator component is in charge of generate the actual proxy code in the target language/platform using one of the specialized generators.

In the next figure you can see all the available proxy generators. Some of them are there since Delphi XE but all the mobile platforms have been added in XE2.

That’s all for now.

RAD Studio XE2 will be officially presented all over the world during the “RADStudio XE2 World Tour”.

You can find the list of all launch events in the RADStudio XE2 World Tour page.

I’ll be a presenter at 3 launch events in Italy and United Arab Emitates.

These are the events where I’ll be (click to register):

RAD Studio XE2 had a lot of new features. This is really the BEST ever Delphi version since version 1.

I’ll blog about other XE2 features mostly Delphi related (as usual) so stay tuned.

“DataSnap and Android (Part I)” on BlaisePascal

Android, Delphi XE, Magazines 43 Comments »

BLAISE PASCAL MAGAZINE
Issue no.17 is just published.

In this issue there is the first part of my articles about “DataSnap and Android”.

During this series I’ll show how to write a complete TODO application using Delphi DataSnap Server and an Android thin client.

Have a good reading.

AndroidConference in Italy - Call4Papers

Android, ITDevCon2011, Programming 17 Comments »

The Android Conference

Yes! This is a great news! Before the two-days conference dedicated to Delphi, this year there will be the AndroidConference.

The Android Conference

The Android Conference will be a conference focused on Google Android development. Android is one of the most popular OS in the world. Now you can use it for your mobile applications.

And now, the “official” Call4Papers Announce

Dear potential AndroidConference speaker,
I’m building the agenda for the first Android Conference in Italy that will be held in late October in Verona. Dates will be announced ASAP.
The call for papers is officially open right now, so if you want to propose some speeches, I’ll be glad to evaluate them.

For the Call4Paper I need:
• Title (for every talk)
• Abstract (for every talk)
• Difficulty level (for every talk. Difficulty level is a scale from 1 to 3 with the following mean: introduction, intermediate, advanced)
• Speaker’s photo
• Speaker’s profile
I’m looking forward to your proposal. The call4papers ends June 30th, 2011.
Please, send your proposal to this email address.
Proposals will be evaluated and the speakers will be contacted ASAP.
This year topics will be the following:

Topics
- Android Fundamentals
- Android Advanced
- Working with Android Sensors
- Android@Home
- Games
- OpenGL
- Android ADK
- Android Market best practices
- Design UI Pattern
- Optimizing you app for the mobile world
- Developers Tools
- 3rd part libraries
- Android NDK
- The WebView World
- Using WebServices
- SOA and ROA
- HW integration

Target audience
- Software architects
- Software developers
- Project managers
- IT managers
- Trainers
The conference web site is http://www.itdevcon.it (still under construction).
Thanks and hope to see you at AndroidConference 2011.

Tomorrow the webinar: “Developing Application Services using PHP Servers and Android Clients”

Android, Programming, RADPHP, Video 30 Comments »

Developing Application Services with PHP Servers and Android Phone Clients

Developing Application Services with PHP Servers and Android Phone Clients

In this webinar I’ll show how to develop Android application talking with REST PHP WEB Services. After introducing the basic concepts, attendees of this session will be taken through how to REST-enable the server application, before building the client application targeting an Android phone.

Topics covered in this webinar include:

  • Introduction to REST and JSON support in PHP
  • Introduction to Android client development
  • Creating a REST web service with RadPHP
  • Connecting from an Android application to the REST web service

Companion White Paper, Videos and Source Code Visit the RAD Studio in Action – PHP and Android Resource Center for additional information on this topic, including an in-depth technical white paper, example source code and a video series on building applications with PHP and Android.

More info on http://www.embarcadero.com/rad-in-action/php-android

Developing Application Services with PHP Servers and Android Phone Clients

Android, Programming, bit Time Software 24 Comments »

My new white paper about “Developing Application Services with PHP Servers and Android Phone Clients” is on line under the Embarcadero RAD-in-Action initiative.

Developing Application Services with PHP Servers and Android Phone Clients

Developing Application Services with PHP Servers and Android Phone Clients

Are (or will be) available:

  • The White Paper
  • The complete source code from the white paper
  • 2 videos showing a complete (obviously very simple) Android application interfacing with a PHP REST web service (developer with RAD PHP XE).
  • A webinar (9th february)

In bit time we are heavily working with the Android operating system used in conjunction with DataSnap or PHP services.

This RAD-in-Action initiative (sponsored by Embarcadero) should be useful for all who want to start to work with Android and REST web services developerd with (RAD)PHP or Delphi Datasnap.

Back from Brazil (all slides and code from the Brasilian Delphi Conference)

Android, Delphi XE, Embarcadero, Events, bit Time Software 54 Comments »

Last week I returned from Brazil where I had been to speak to the Delphi Conference.
The conference was held in St. Paul who, like many Brazilians will be able to confirm, is not a typical Brazilian city.

The warmth of local people has been exemplary. Andreano Lanusse has organized all in a really valuable way.

Besides the excellent food, I was surprised by the number of Delphi developers found: 550! In addition, over 150 people
have not had time to register and were placed on a waiting list. Fantastic.

After the inevitable David and his keynote, there were four simultaneous tracks during the day.

My talk was translated from English to Portuguese.

As imagined, the argument Android and seem to raise much interest in the Delphi community.

It was very nice to have confirmation in the first person to what is present and the large Brazilian community Delphi.

Here you can find all the slides and in my GoogleCode svn repository you can find all the DEMO code.

If you live in italy or can speak in italian language, you might be interested in the “ITDEVCON MOBILE BOOST” (http://www.itdevcon.it/).

Stay tuned.

RADSTUDIO XE LAUNCH in Rome and Milan

Delphi XE, Embarcadero, ITDevCon, ITDevCon2010, Programming, RAD STUDIO XE, bit Time Software 44 Comments »

This year, the launch of the new RADSTUDIO XE has been really nice. We have met some friends and customers exciting to see the new Delphi features and capabilities.
In the event of Rome there was DavidI too.

The agenda has been the following:

Embarcadero Update + XE and All-Access (DavidI)
+ New Products, Ideas, Projects
+ Delphi64 bit compiler preview
+ MACOSX FishFacts DEMO

What’s New in the IDE (Marco Cantù)
+ SubVersion
+ BeyondCompare
+ AQTime

New features in the RTL, RTTI (Daniele Teti)
+ Threading
+ JSON
+ Virtual Methods Interceptor
+ RegEx
+ CodeSite Express

Agile Development (Daniele Teti)
+ UML modeling
+ audits, metrics
+ repository
+ unit testing
+ Final Builder

Web, Cloud e Database Support (Marco Cantù)
+ Microsoft Azure Components
+ Deploy in the Amazon EC2 Cloud

What’s new in Datasnap (Daniele Teti and MArco Cantù)
+ Developing DataSnap server (Daniele)
+ DS Authentication/Authorization (Daniele)
+ DS Filters (Daniele)
+ DS RequestFilters (Marco)
+ Using DS from Delphi Client (Daniele)
+ Using DS from PHP Client (Daniele)
+ Using DS from Javascript Client (Marco)
+ Using DS from Android Client (Daniele)

Summary and Q&A

The last DEMO has been an Android APP wich use a REST DataSnap Server built with Delphi. Audience has been very excited about it.

Many attendedees have been very interested in the upcoming ITDevCon (www.itdevcon.it) and for the new courses in the bit Time offers.

Some of the photos are uploaded on Google Picasa. You can see them here.

Sneak preview about DORM, The Delphi ORM

Design Patterns, Programming, RTTI 24 Comments »

My yesterday post about this busy time, have raised some interest about DORM, the Delphi ORM.

So, also if I still haven’t released any files, wish to expose some internals about DORM.

DORM is an implementation of the DataMapper design pattern written having Hibernate in mind.

It’s completely unit tested and have the following features:

  • External file mapping. (JSON format)
  • Persistence ignorance (every TObject can be persisted)
  • Support for One-One and One-Many relations (still no many-many)
  • Support for LazyLoading (you can enable§/disable lazyloading by file or by code by per-basis needs)
  • Support for IdentityMap
  • Support for custom “finder” (you can still use complex SQL if you want)
  • Complete support for CRUD
  • Transactions
  • Built in logging system to log *EVERY* sql or action performed by the framework
  • Opened to multiple data access strategies (interfaced based, not inheritance based) for use with different database (now I’ve developed the firebird one using DBX)
  • Caching for RTTI (the TSession object have a single TRttiContext holding ALL metadata)

Code is still under heavely development.

Those are 2 test-method to show the use of DORM:

  1. TPerson = class(TObject)
  2. property Phones: TdormCollection…. //implements IList
  3. end;
  4.  
  5. TPhone = classs(TObject)
  6. end;
  7.  
  8. //and now the unit tests
  9.  
  10. procedure TTestDORMHasMany.Setup;
  11. begin
  12.   Session := TSession.Create;
  13.   Session.Configure(TStreamReader.Create('dorm.conf'));
  14. end;
  15.  
  16. procedure TTestDORMHasMany.TearDown;
  17. begin
  18.   Session.Free;
  19. end;
  20.  
  21. procedure TTestDORMHasMany.TestHasManyLazyLoad;
  22. var
  23.   p: TPerson;
  24.   t: TPhone;
  25.   guid: string;
  26. begin
  27.   p := TPerson.NewPersona;  //static method. Return a fully populated TPerson object
  28.   try
  29.     t := TPhone.Create;
  30.     p.Phones.Add(t);
  31.     Session.Save(p);
  32.     guid := p.guid;  //GUIDs, or other PK types, are generated automagically by DORM. Obviously there is a specific class loaded to do this specified in the dorm.conf file)
  33.   finally
  34.     Session.Commit;
  35.   end;
  36.   Session.StartTransaction;
  37.  
  38.   // Test with lazy load ON
  39.   Session.SetLazyLoadFor(TypeInfo(TPerson), 'Phones', true);
  40.   p := Session.Load(TypeInfo(TPerson), guid) as TPerson;
  41.   try
  42.     CheckEquals(0, p.Phones.Count);
  43.   finally
  44.     Session.Commit;
  45.   end;
  46.  
  47.   Session.StartTransaction;
  48.   // Test with lazy load OFF
  49.   Session.SetLazyLoadFor(TypeInfo(TPerson), 'Phones', false);
  50.   p := Session.Load(TypeInfo(TPerson), guid) as TPerson; // Without commit, AV becouse IdentityMap doesn't work properly
  51.   try
  52.     CheckEquals(1, p.Phones.Count); // Child objects are loaded
  53.   finally
  54.     Session.Commit;
  55.   end;
  56. end;
  57.  
  58. procedure TTestDORMHasMany.TestLoadHasMany;
  59. var
  60.   list: IList;
  61.   t, t1: TPhone;
  62.   p: TPerson;
  63.   guid: string;
  64. begin
  65.   p := TPerson.NewPersona;  //static method. Return a fully populated TPerson object
  66.   try
  67.     t := TPhone.Create;
  68.     t.Numero := '555-7765123';
  69.     t.Kind := 'Casa';
  70.     p.Phones.Add(t);
  71.  
  72.     t1 := TPhone.Create;
  73.     t1.Number := '555-7765123';
  74.     t1.Kind := 'Casa';
  75.     p.Phones.Add(t1);
  76.     Session.Save(p); // save Person and Phones
  77.     guid := p.guid;
  78.   finally
  79.     Session.Commit;
  80.   end;
  81.  
  82.   Session.StartTransaction;
  83.   p := Session.Load(TypeInfo(TPerson), guid) as TPerson;
  84.   try
  85.     CheckEquals(2, p.Phones.Count);
  86.   finally
  87.     Session.Commit;
  88.   end;
  89. end;

Mapping, contained in a file called “dorm.conf”, is similar to the following:

  1. {
  2.   "persistence": {
  3.     "database_adapter": "dorm.adapter.Firebird.TFirebirdPersistStrategy",
  4.     "database_connection_string":"127.0.0.1:C:\\MyProjects\\DORM\\experiments\\dorm.fdb",
  5.     "username": "sysdba",
  6.     "password":"masterkey"
  7.     },
  8.   "config": {
  9.     "package": "dorm.bo.Person",
  10.     "logger_class_name": "dorm.loggers.FileLog.TdormFileLog"
  11.   },      
  12.   "mapping":
  13.     {      
  14.       "TPerson":
  15.       {
  16.         "table": "people",
  17.         "id": {"name":"guid", "field":"guid", "field_type":"string", "size": 100, "default_value": ""},
  18.         "fields":[
  19.           {"name":"firstname", "field":"first_name", "field_type":"string", "size": 100},
  20.           {"name":"lastname", "field":"last_name", "field_type":"string", "size": 100},
  21.           {"name":"age", "field":"age", "field_type":"integer"},
  22.           {"name":"borndate", "field":"born_date", "field_type":"date"}
  23.           ],
  24.         "has_many":[{
  25.           "name": "Phones",
  26.           "class_name":"TPhone",
  27.           "child_field_name":"guid_person",
  28.           "lazy_load": false
  29.         }],
  30.         "has_one": {
  31.           "name": "car",
  32.           "class_name":"TCar",
  33.           "child_field_name":"guid_person"
  34.         }
  35.       },
  36.       "TPhone":
  37.       {
  38.         "table": "phones",
  39.         "id": {"name":"guid", "field":"guid", "field_type":"string", "size": 100, "default_value": ""},
  40.         "fields":[
  41.           {"name":"number", "field":"number", "field_type":"string", "size": 100},
  42.           {"name":"kind", "field":"kind", "field_type":"string", "size": 100},
  43.           {"name":"guid_person", "field":"guid_person", "field_type":"string", "size": 100}
  44.           ]
  45.       }
  46.     }
  47. }

The PODO (Plain Old Delphi Objects) can be binded to the VCL controls with a set of MediatingView (Model-GUI-Mediator Pattern) with an Observer mechanism to mantain things in synch.

Any comments? Someone interested?

Delphi Day 2010

Continuous Integration, Delphi 2010, Events, Programming, bit Time Software No Comments »

Also this year I was at Delphi Day with many others bit Time co-workers.
This year I did a speech about Continuous Integration and Unit Test with Delphi.

I showed some of the methodologies and tools that we used in bitTime for long and for whom we also offer training.

Many Delphi programmers and companies should consider adoption of this tecnique for do more and better with the same effort (and the same money).

The event was interesting and was also an opportunity to meet some of the Italian Delphi programmers with which to meet and exchange ideas.

Marco wrote a nice summary of the event in his blog.

My interview at PHP Day 2010 has been published

Continuous Integration, Programming, bit Time Software 2 Comments »

My interview at PHP Day 2010 has been published on php.html.it.

This is the link to the article.

This is the video on youtube.

The interview is only in italian language.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in