Monthly Archives: September 2019

Learn How To Deploy Delphi 10.3 Rio FireMonkey Apps In The Cloud Via HTML5

Delphi 10.3 Rio FireMonkey apps are cross platform with a single codebase and single UI that target the Android, IOS, Macos, Windows, and Linux platforms (FMXLinux was recently added to Delphi 10.3 Rio Enterprise and Architect). You can also deploy Delphi FireMonkey apps to the web using websockets and HTML5. The method for doing this is basically the FireMonkey app runs on a Windows or Linux server and it’s canvas draws are sent to the web browser via a websocket. Each user connection runs one copy of the app on the server (so one user one app). The server is running the app so it needs enough hardware for however many concurrent apps you want to run.

For FireMonkey Windows apps this can be achieved through Thinfinity VirtualUI. Thinfinity is a commercial product which a cost per concurrent user. The user connects to the Thinfinity server, Thinfinity launches the FireMonkey app, handles the user input, and sends the drawing to the browser client. Thinfinity has been around for quite a few years and I would consider it a pretty mature product. It supports enterprise features like load balancing and ActiveDirectory login. You can also use it with Windows apps written in other languages (like C++ and C#).

For FireMonkey Linux apps this can be achieved through FMXLinux and Gtk Broadwayd. FMXLinux is also a commercial product but has recently been made available to Delphi 10.3 Rio Enterprise and Architect developers for free (just open GetIt and install it). FMXLinux allows FireMonkey apps to run on Linux desktops using the Gtk UI library. Gtk comes with an application called Broadwayd which will stream the Gtk app out to HTML5 via websockets. Broadwayd runs on a single port (8080) per app and you can click compile in Delphi 10.3 Rio and see your FireMonkey app in the browser served up from you Linux machine if you start the broadwayd server prior to deployment. If you want to run a pool of FireMonkey apps on Linux like Thinfinity does on Windows you can set up a Linux bash script to do so.

The purpose of the bash script is to run X number of FireMonkey apps through broadwayd (remember 1 app per port) and then use a load balancer make all of the apps accessible via a single port. In order to do this second part there is a Linux package called balance which can do this for you. One limitation of it is that it will only do 16-32 apps in it’s app pool unless you compile the source yourself. You can install balance with “sudo apt install balance” on Ubuntu or “yum install balance” on CentOS. Broadwayd and balance are open source and free applications but the solution is also not as polished as Thinfinity UI. You could also build something in Delphi using TidMappedPortTCP instead of using balance. For commercial deployments I’d recommend going with Thinfinity though.

Here is the sample bash script I put together which handles hosting multiple apps on a single port for you. Save the script as gtkcloud.sh and “chmod +x gtkcloud.sh”. It takes two parameters. The first parameter is the path to the app you want to run and the second parameter is the port you want to run the load balanced app on.

#!/bin/bash
for i in {1..16}
do
    nohup broadwayd :$i &
    export GDK_BACKEND=broadway
    export BROADWAY_DISPLAY=:$i
    $1 &
    #echo ""
done

servers=""

for ii in {1..16}
do
    let port=8080+$ii
    servers="$servers localhost:$port:1 %"
done

echo $servers

balance $2 $servers

Example usage is as follows and would host 16 instances of /root/FireMonkeyPaintDemo on port 81.

./gtkcloud.sh /root/FireMonkeyPaintDemo 81

And that is all there is to it. You can run your Delphi FireMonkey apps on Android, IOS, Macos, Windows, Linux, AND the web using a single codebase and single UI.

Download the gtkcloud broadwayd + balance bash script for hosting Delphi FireMonkey FMXLinux apps.

Don’t have Delphi 10.3 Rio Enterprise or Architect? You can still use FMXLinux with you Delphi Pro FireMonkey apps.

Head over and check out the full website for FMXLinux and learn about deploying Delphi desktop apps to Linux.

Tags: , , , , , , , , , ,

Anatomy Of A Delphi 10.3 Rio Firemonkey App On #Android, #IOS, #Windows, And #macOS

If you are new to working with a full featured framework like Firemonkey you may be wondering at the size of the apps that Delphi 10.3 Rio Firemonkey generates. The Firemonkey Framework has hundreds of thousands of lines of code that allows you to jump ahead and start building the app you want to build now instead of the bricks in the road to get there. Hopefully this infographic will provide some insight into what makes up an APK/IPA cross platform application deployed from Delphi 10.3 with the FMX framework. The infographic covers Android, IOS, Windows, and Mac OSX apps/packages/libraries/archives created using the Firemonkey framework. Tools that utilize the Firemonkey framework are Delphi 10.3, C++Builder 10.3, and RAD Studio 10.3. The infographic only covers Release mode (something you could deploy to your customers). I have also included a VCL section in the infographic so that you can compare the Windows only VCL framework to the cross platform FMX framework. Also keep in mind that when you use debug information or are in Debug mode your file could be significantly larger. The sizes of the generated files are included in the green circles. There is the normal compiled size and then there is the compressed or packaged size. APK and IPA files are packaged and compressed. The compressed sizes for Windows and Mac OSX were achieved using the 7Zip format. Here is some information directly from the infographic as well about what units are included in a FMX app on Android (it is slightly different on each platform) and how those units effect the size of the deployable file.

Let’s start off with a Hello World app which is basically a FMX form with a TLabel on the form. This comes out to around ~5.88MB when deployed to Android as an APK. Even though this is a Hello World app there is already much more functionality here than just the ability to print out ‘Hello World’ to the screen. A true ‘Hello World’ would be much smaller because it would lack these Firemonkey framework units. The FMX and RTL units included are:

System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls

Next up I’ve listed what I call a Basic App that clocks in at ~6.45MB. A basic app has some more visual controls available to it like a TListView, a TEdit, a TListBox, a TTabControl, a TMemo, and even some access to advertising. Here are the FMX units included (in addition to the units from the Hello World app):

FMX.ListView.Types, FMX.Memo, FMX.ListView.Appearances, FMX.ListView.Adapters.Base, FMX.Advertising, FMX.TabControl, FMX.ListBox, FMX.Layouts, FMX.Edit, FMX.ListView, FMX.ScrollBox

This next tier of app size I’ve termed Services because it is basically some Android JAR files which when fully included bring the app up to around ~6.61MB. These services are basically helper services for Android (some of which are provided by Google) like Google IAP, GCM, and Analytics. You can include and exclude each of these files from your APK separately. Here is a list of the additional files:

android-support-v4.dex.jar, cloud-messaging.dex.jar, fmx.dex.jar, google-analytics-v2.dex.jar, google-play-billing.dex.jar, google-play-licensing.dex.jar, google-play-services-*.dex.jar (there are a number of play services covered by this wildcard)

Next up we have what I have termed the Consumer App style app tier which rings in at around ~9.50MB. Obviously if you add more or differently functionality the size of your app can fluctuate greatly. You could also build games and they might fall in this size range depending on how many external graphics and sound you used. This type of app includes more functionality like the RESTClient, the in app purchases unit, sensors, a grid component, and the camera component. Here are the additional FMX and RTL units included by the IDE when these new components (in addition to all of the above) were added:

System.Sensors, System.Rtti, FMX.Grid, System.Sensors.Components, FMX.Media, REST.Response.Adapter, REST.Client, Data.Bind.Components, Data.Bind.ObjectScope, System.Actions, FMX.ActnList, FMX.InAppPurchase

Lastly we have the Enterprise and Database App tier which comes in at around ~11.1MB+ but can increase size from here the more you add to your app. This includes FireDAC functionality for accessing an SQLite database, LiveBindings to bind the data to a grid, accessing various path utility functions, and creating ini files for settings storage. At this level you can add tens of thousands of lines of code and lots of forms and the app could still be around this size. The RTL and FMX units included when this functionality was added (in addition to all of the above units) are as follows:

FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, Data.DB, FireDAC.Stan.ExprFuncs, FireDAC.Phys.SQLiteDef, System.Bindings.Outputs, Fmx.Bind.Editors, Data.Bind.EngExt, Fmx.Bind.DBEngExt, Data.Bind.Components, Data.Bind.DBScope, FireDAC.Phys,FireDAC.Phys.SQLite, FireDAC.Comp.Client, Fmx.Bind.Grid,FireDAC.Phys.SQLiteVDataSet, FireDAC.Comp.DataSet, System.IniFiles, System.IOUtils, FMX.Grid.Style, Data.Bind.Grid, REST.Types, Data.Bind.ObjectScope

You can also take a deep dive into the Firemonkey Framework itself using the Delphi Unit Dependency Scanner. The unit dependency scanner will show you all of the units that your app uses and all of the units that those units use in a treeview. It will also show line numbers of each unit and a total line number count of your entire project.

You can find out more about the Firemonkey Framework on the Embarcadero DocWiki and on the FiremonkeyX website.

Download the full Anatomy of a Firemonkey Framework Multi Platform App infographic for future reference.

Tags: , , , , , , , , , , , , , ,