Delphi Handbooks Collection


Delphi XE Handbook


Delphi 2010 Handbook


March 5, 2012

DataSnap Clients for FireMonkey iOS in Update 4

Delphi XE2 Update 4 adds a very significant extension to FireMonkey on iPhone and iPad: The Ability to create DataSnap client applications for these devices in a very simple way.

Delphi XE2 Update 4 adds a very significant extension to FireMonkey on iPhone and iPad: The Ability to create DataSnap client applications for these devices in a very simple way. This is an extremely relevant element of the FireMonkey architecture, and pushes it considerably, that's why it is a bit odd this is not mentioned in the Release Notes for Update 4. maybe they want to keep this secret... of offer it as a surprise to the webinar this Wednesday on Mobile development. If this is the case, sorry to spoil the surprise. Enough preamble, let's see what's available and how to proceed.

First, create a DataSnap server application of any kind, use HTTP (as we are going to use the REST) interface, and enable the use of the Mobile Connectors:

Now run the DataSnap server and connect to it to download the FreePascal support units and proxy class:

      http://localhost:8080/proxy/freepascal_ios50.zip

Copy these files in a folder, create a new FireMonkey HD iOS application,, saving it in the same folder, add an edit box and a button, and write the following code:

Not the best coding style (for the repeated initialization and missing try/finally blocks) but should give you a good idea. Of course, change the IP address of the machine hosting the server application as seen from the iOS device (so, no "localhost" allowed). You can now compile in Delphi, but cannot run it, as the connection object used is specific to iOS. If you run it on Windows you'll get an exception when the connection is created. Still, you can extend the code with IFDEF statements to have a Windows version.

Now export the project to XCode, go to your Mac, open the project in XCode, compile... and you'll likely see an error. In one of the support units, DSRESTConnection.pas there are references to other units with the wrong case ("Rest" instead of "REST") and since the Mac file system is case sensitive, you'll get compiler errors. Fix this, compile and run, and the program can show up on your phone in a second. Here is it on my iPad (kind of a bare form, but this was just a proof-of-concept):  

The program works and all the development took less than 15 minutes, plus the time to found the bug. Very fast and clean. I've already created another more complex client application with the same structure.





 

8 Comments

Which font are you using? 

This is not about the your blog post. 
I'm wondering which font are you using for coding? It 
seems nice to me :)
Sory for that.
Comment by Namık Kemal Karasu [http://nkkarasu.net] on March 5, 18:27

DataSnap Clients for FireMonkey iOS in Update 4 

Is there a reason that you used this odd ownership
model? You create both, the connection and the proxy,
with owners and at the end you free them explicitly
again. 

This would work perfectly fine of course, but on
mobile devices CPU cycles are still somewhat expensive... 
Comment by Olaf Monien [http://www.monien.net/blog] on March 5, 19:42

DataSnap Clients for FireMonkey iOS in Update 4 

Namik,

it is called Pragmata, I blogged about it at 
http://blog.marcocantu.com/blog/pragmatapro_font_delphi.
html

Olaf, you are right, the original code was different 
(and data was kept around) but I put everything in a 
single method for simplicity, and it doesn't make a lot 
of sense the way memory is managed. Still the point is 
to show how easy it is now to make a DataSnap call in an 
iOS Delphi application. 

-Marco
Comment by Marco Cantu [http://www.marcocantu.com] on March 5, 20:56

DataSnap Clients for FireMonkey iOS in Update 4 

Hi Marco,

I have an immense respect for you work and knowledge 
about Delphi, but please, put TSomething.Create and 
TSomething.Free protected by a Try..Finally block, 
would you? ;-)
Comment by Alexandre Machado [http://alexandrecmachado.blogspot.com] on March 6, 06:04

DataSnap Clients for FireMonkey iOS in Update 4 

Alexandre,

 if I write "Not the best coding style (for the repeated 
initialization and missing try/finally blocks)" this is 
quite a clear indication, isn't it? I though of putting 
the listing as code in the HTML page, and given I have 
formatting issues wanted to keep the code easy to 
format. Also, the code should have created the objects 
only once, with an owner, and used those objects without 
freeing them... but again, I wanted to show FireMonkey 
DataSnap iPad client, not coding style...

-Marco
Comment by Marco Cantu [http://www.marcocantu.com] on March 6, 08:08

DataSnap Clients for FireMonkey iOS in Update 4 

 Hi Marco, I was joking, of course. Although I think we 
have to take special care about code snippets because a 
lot of beginners just copy and paste, and voilá... a 
time bomb ready to do some damage! ;-)
Comment by Alexandre Machado [http://alexandrecmachado.blogspot.com] on March 6, 12:49

DataSnap Clients for FireMonkey iOS in Update 4 

Please see QC#103021 for fixing a fatal bug.
http://qc.embarcadero.com/wc/qcmain.aspx?d=103021
Comment by Tomohiro Takahashi on March 8, 11:38

DataSnap Clients for FireMonkey iOS in Update 4 

Thanks Marco,

Can we also have push a "call back" to the iPhone 
application designed by Firemonkey?

 
Comment by Navid on March 26, 18:41


Post Your Comment

Click here for posting your feedback to this blog.

There are currently 0 pending (unapproved) messages.