Mobile Apps Development using Delphi

Hello everybody!

Today’s topic is about mobile apps development using Delphi. This article is for people who are already using Delphi for desktop development and just heard something or thought that they have to improve their software and add for example mobile (cell phones and tablets) support. Let's start. In the beginning, a few words about our company. Our company is headquartered in Eastern Europe in Minsk. Minsk is the capital of Belarus, its population is about two million people and we specialize in legacy software modernization and enterprise grade apps and software development. For Delphi we are performing migration from all legacy versions to up-to-date or to some other technologies. Also we develop applications from the scratch, perform enhancement and re-engineering of software, and, as I told, we are experts in Delphi development. In Softacom we help enterprises to get through the digital transformation modernizing legacy software and developing new one.

Now let's talk about our today's plan. Today we will discuss such questions: what is Delphi today, the reasons to continue using Delphi, why we have to think about shifting to mobile platforms, how can we develop mobile apps (native, cross-platform, hybrid, progressive web apps), what does Delphi offer us for mobile apps development, and after that we will talk about two options which we can choose using Delphi for mobile apps development. One of them is FireMonkey Cross-platform framework and as for the second one we will discuss how can we build mobile applications using TMS WEB Core framework. In the end I will provide you some helpful resources which you can use for starting your mobile development using Delphi.

Today I'd like to refresh in our minds some history. If you have already participated in our webinars you have already saw some of the slides. That’s all for new people. Anyway, let's just refresh what is Delphi today and in the past. Delphi is a software development tool used to build desktop, mobile, and different IOT software today. Delphi is up-to-date despite it was developed in 1995. The reason for it is that it's been regularly updated by Embarcadero, at least, according my information, we have a couple of releases per year and Embarcadero keeps it up-to-date. It was really and even now it is a huge Delphi community comprised with very experienced engineers and developers. It was a revolutionary technology for rapid application development in the 90s and 2000s. It was a really unique tool which you could use for desktop development compared with this ugly Microsoft Visual Studio 6 version. It was too hard to start the development of the application with Visual Studio 6 if compared with Delphi where you could just create the project put the controls and run. And the miracles happened. Interesting fact that the Chief Architect behind Delphi was Anders Hejlsberg who was later persuaded to move to Microsoft where he worked as a lead architect of C#. I provided such information here just like a food for the thought. And after that in 2003 Microsoft introduced .NET/C# and Visual Studio 2003 which in my point of view is a Microsoft version of RAD studio, and spent a lot of money into advertisement and marketing of these tools, the popularity of Delphi started decreasing and eventually .NET caught the leadership.

The reasons to continue using Delphi. We will divide this question in two parts. We will talk about pros and cons because, of course, we have pros and cons and we should be objective. Delphi is a cross-platform tool. Today you really can develop application for iOS, Android, I'm not talking about Windows, it's like a must-have, you can develop application for macOS or application for Linux. Easy to use and designed for rapid development approach for desktop development. According to my experience it's really easier and really more rapid development if compared with WPF which of course has a much richer UI than WinForms but it's really much harder to develop WPF UI applications as compared with Delphi. But if we're talking about WinForms I cannot even compare it with Delphi because WinForms is very weak in UI and possibilities and it's not easy to improve the UI of WinForms applications. Easy to deploy since executables don't need any pre-installed frameworks, and hence there is no headache about frameworks versioning, packages versioning, etc. And this is what I mean. If you have, for example, some .NET application you should know which .NET version your clients have, which packages they have, how it will be, will they have any conflicts, and you have to deploy assemblies and there is a lot of questions. Even today Delphi has a huge set of 3rd party components, for example look at TMS Software set. It’s a really huge set of components which can cover UI, background operations or show media, different cross-platforms controls, web controls and so on. Of course, one more advantage is regular new releases of Delphi and RAD Studio from Embarcadero. As a pro, we have a lot of software which was developed using Delphi. Right now you can really migrate that legacy software written using for example Delphi 5, Delphi 7 to the up-to-date Delphi versions without rewriting it from the scratch. If your software has a lot of background logic, you can keep 90-95% of your code. Of course, like a remark, only if you don't need a code review and rewriting your code and rewriting spaghetti.

Cons. Two major cons in my point of view are future risks and negative information noise. Future risks: this is what I'm hearing from our clients and our partners: will Embarcadero have enough resources to compete on par with other development tools? Will we have enough specialists and developers on the market for supporting and developing our software? And these questions are really importan. Right now even we are fighting for Delphi and trying to be like Delphi evangelists explaining people why they don't need to be scared. Negative information noise: in the 90s and 2000s Delphi was studied in universities and now it's replaced by other tools. Last year, as I remember, Embarcadero introduced a free version of Delphi (Community Edition) and now maybe different universities will again continue using Delphi and young people will study it during their classes. Again, today young developers consider Delphi to be obsolete, not fashionable technology. They don't have any facts. This is what they just hear and this is what I'm calling a negative information noise. Delphi is not an operating system owner. So this is self-explanatory why it's always half a step back from Microsoft, Apple or Google. When Microsoft already developed something, implemented in their development tools, Embarcadero needed time to add the support of these new features in their Delphi. That's life. Again, my point of view, Delphi is not suitable for web development. I am talking about web development in classic understanding. If compared with native web technologies like Visual Studio and ASP.NET, Apache and PHP, you don't have a native for Delphi. Time consuming for the development of complex mobile applications. It's not easy to implement any custom SDKs from Facebook, Google or Apple which are not supported in FireMonkey by default. This is a very serious disadvantage. Sometimes if you are using native tool for Android development, like Android Studio, for implementing a new version of SDK from Facebook you will need maybe a couple of hours, but for Delphi, unfortunately, if you're not experienced it can take two days, a week, and so on.

I think it's a very clear question: why do we have to think about mobile platforms today? Here I just provided some numbers. Of course, it's too hard to measure what people are using, which development tools they are using and I based my numbers on the traffic in the web. Because right now web is everything. Clients generate traffic and based on this I just measured which tools people are using. You can see that in 2010 95% was desktop traffic. In 2015 - it's almost 60 percent. If we're talking about 2019 finally mobile apps traffic won. This information is for April. People got used to mobile apps and they like them. This is why these numbers are so high. Here are exact numbers based on the StatCounter service.

Now let's discuss how can we develop mobile apps at all. In Softacom we have experience almost with all of these techniques and we developed commercial apps using all these technologies, techniques, frameworks, and tools. And again, we will discuss pros and cons. I divided all the types of development tools for mobile applications in three parts: native, cross-platform (hybrid), web based. And there is no standard which can tell you that exactly this tool belongs to this type. Now it's a little bit blurred and one tool can belong to two different types.

Let's start with pros of native development. I will talk about XCode and Android Studio. Xcode for iOS, it can be Objective C language or Swift and Android studio like JavaScript, Kotlin for Android. The main advantage is that it has the best speed and performance. They are trying to develop the tool which will be closest to the platform, to the device, to the operation system. Permanent support of newest features and up-to-date documentation. All other tools like cross-platform, hybrid should again implement all these new features in their tools. Publishing to app stores - the typical way of app distribution for people. Cross-platform applications are also published to app stores. But here you're protected hundred percent, it has lower risks during publishing to app stores. Available SDKs from all vendors. If we have any source hardware, third-party services, SDKs - all of these vendors in the first place will develop SDK for native platform: for Xcode and Android Studio, and it's a very good benefit.

Now about cross-platform. The idea of all these cross-platform tools is a re-usable source code for different platforms. Yes, theoretically you can write some code only once and use it in different platforms. In real life it's not so easy of course. Because different platforms again have different techniques, different nuances which you have to implement in your code. As for UI: sometimes it can be a common UI but sometimes you have to create forms, controls, different versions for each platform. Publishing to app stores. Cross-platform tool creates a native package for the app store: for the Apple App Store and Google Play Market. Possibility to use the same knowledge which you are using for desktop. Because sometimes if we're talking about Delphi we can develop application for desktop and then with FireMonkey import it to the mobile. Better development speed for not very complex apps. Again, because of re-usable code, re-usable UI. And it can be cheaper up to 30-40% compared with native while developing apps for both iOS and Android platforms even if you have different UI and you need time for implementing all necessary SDKs sometimes.

Now web based apps. It is a very famous technology nowadays – PWA or progressive web application. It includes a lot of different tools, frameworks. JQuery, Bootstrap, React.js, Angular and so on. App can work everywhere where you can use web browsers. This app really can work on desktop, Mac OS, iOS, Android, Linux – it doesn't matter. It even can work without internet connection. When you are opening the application it can cache the application on your device and using JavaScript it caches a lot of logic, pages, and your application can work even without internet connection. For example, the data retrieval from the web, from the server, theoretically can work without internet connection like regular application. You even will have an icon on your desktop. Possibility to apply the same knowledge which you are using for web development: C#, HTTP/CSS/JavaScript. Update process of your applications is easier. You can change the app HTML/CSS/JavaScript files on the server only once and all users will have this update and the they won't need to update the app in the App Store. If we're talking about native apps, you have to control that your users updated your application, that they use the latest version without the bugs which you fixed.

Now cons. Today it's not enough to have for example application for iOS or for Android if this is commercial application, not some specific service application. If this is an application for everybody, like e-commerce, you should have this application for both platforms, at least for two platforms: iOS and Android. It will be different tools for different platforms, not reusable source code. You will need different resources and different specialists. Of course, maybe you have a guy who knows Android and iOS, and he can use two different platforms, but anyway, you have to multiply his time for developing two versions of your application. It's not for one person. If we're talking about cross-platform, it can be one guy who can develop your application on all platforms. If we're talking about cross-platform, it's usually not hundred percent platform support. This is what I talked about. For example Delphi. I'm not sure how it is right now, but for example previously it didn’t have a support of some things. For cross-platform SDKs availability is worse than for native tools - like an example, if you need the latest Firebase and Facebook SDKs support, you have to wait or develop it yourself. As I remember, Embarcadero released maybe a couple of days ago Firebase support for Delphi and that’s great but this is just an example. In real life you have hundreds and thousands different SDKs for different third-party providers, integrations for different systems and so on. If we're talking about web-based, you need web hosting. You have to store somewhere your web application or PWA application. It can web hosting or virtual machine which is much more expensive and can have a lot of headache. Limited support of distribution via app stores. I think that's very important because for people it is a typical way: go to App Store to download an application. It is not like “You should go to my website, check this link, open something and the application will be installed”. Sometimes it's a disadvantage. But sometimes you cannot deploy your application according app stores policy. For example, for some industries which are prohibited in app stores. They can develop a portable web application and deploy it via your website and do another architecture. In this case it will be an advantage.

Now let's talk about what does Delphi offer us for mobile apps development. It can be different variants, different options. Here I provided only the most popular which we used. We have a lot of experience with such realizations. The first one is classic – FireMonkey Native Cross-platform application. It is an Embarcadero solution. Next one is web application (which is hosted somewhere on the hosting) plus FireMonkey web browser container. And finally for the app store it will look like native application. You won't open it with web browser. It will become a compiled application which will be installed on your phone and it will work like regular native application. The third option which we will discuss today is TMS Web Core PWA project. You can see all these circles which are provided here. It's like an example how it works and which resources will you need for implementation of this techniques. If we're talking about FireMonkey and we will develop iOS application and Android application, for iOS you will need Mac OS, installed Xcode, PAServer from Embarcadero (platform assistant server). Delphi project will connect to MAC, compile your application and your project exactly on Mac OS. And you will have finally an .apk package. It's like applications file for iOS which you can upload to app store using iTunes Connect an application loader from Xcode package. You will need a physical computer with Mac OS, or virtual machine. For Java and Android it's a little bit easier. On the same machine with Delphi you will just compile your application using Java, in the output folder you will have apk package which you can just via browser upload to Google Play market. If we are talking about web app plus FireMonkey it has almost the same process. But you also will need a hosting for your web application. It can be shared hosting or it can be cloud-based hosting like Azure and your web application can be built in any technology you want. It can be ASP.NET, PHP. Communication between your web application and Delphi can be with JavaScript. Delphi has different techniques for this purposes. The third option is TMS Web Core PWA project. In Delphi you will create a specific project which is called TMS Web Core project. It's not like regular VCL FireMonkey project, it's TMS Web Core project and on Delphi machine you will be able to design your application, compile. In the output folder you will have your website and specific files for supporting PWA technology and you will need a hosting like Azure virtual machine or any on premise server. This is like TMS Web Core PWA works.

Now we will discuss deeper how this FireMonkey works. I am hearing a lot of questions “how a cross-platform application can be native?” Yes, it really can. Because of a FireMonkey architecture and how it works. Delphi compiles FireMonkey project to native packages (.ipa and .apk) for iOS and Android which will be deployed to App Store via iTunes Connect and Google Play Market. Embarcadero is calling such solution Native Apps with Single Codebase. On the next slide I will show how it works using iOS. Both platforms Apple and Android accept the packages like native apps, and they even don't know, I think, that they were compiled not using Xcode and Android Studio. You don't need any additional web application, emulators, virtual machines for running the application. Delphi creates a real native mobile applications using XCode and Java compiler. This is what I have already said.

Let's talk about the pros when we are using FireMonkey. You can use Object Pascal code and Delphi IDE for developing iOS and Android mobile applications. You can use the same source code, the same code base, and UI for both platforms. Sometimes you can use the same UI but sometimes it can be a little bit different. But if compared with the other tools, for example Xamarin, they have common UI but they also have possibility to create different UI. From my experience it is a more popular way. But for Delphi you will have one UI for both platforms. You can use compiler directive for platform-specific code. If you have some platform difference because of course hardware is different, operation system is different, and you have a possibility to use the compiler directive, and in the same procedure write a piece of the code which will belong to different platforms.

How does it work? How does it exactly work for iOS? You can see these circles like project life cycle. You're creating FireMonkey Delphi project and add iOS target platform. Then you have to connect Delphi to Mac machine with installed Xcode and Delphi PAServer app. After you establish this connection Delphi compiles the project on the Mac using PAServer and Xcode. PAServer is just an additional application from Embarcadero which helps to communicate Delphi and MacOS. It’s just like a helper for compiling the application using Xcode. And like the result you have compiled .ipa package on the Mac machine in some folder. After that you just can use the XCode Application Loader. Before, of course, you have to prepare the environment for developing your iOS application. You have to perform and finish all your certificates, provisioning profiles… After you made all these steps you can just open Xcode Application Loader, select your .ipa previously compiled with Delphi and upload to iOS. And if everything is okay, add a description and send it to Apple review and after couple of days you can publish your application to App Store.

What about the cons? Of course, FireMonkey does not have 100% of platform support. It is just impossible. A lot of a lot of features which Embarcadero should cover in Delphi and it's a lot of work but maybe not so many people who will use this code because this technology is not too popular. It means, for some functionality available for example from the box for XCode and Android Studio you won't have access for your app. You'll need to learn how to write the wrappers and bridge classes for accessing the missing classes and methods for iOS and Android SDKs. Almost all 3rd-party SDK and API providers have libraries for native platforms, again what I have already said, but for Delphi and FireMonkey it is more like an exception that you will have such support, unfortunately. You will again have to write wrappers and bridge classes for accessing all the SDK methods – this is extra work and your payment for cross-platform benefits.

It was about FireMonkey, now let's talk about Web Core technology. A lot of people ask “is it really possible to create progressive web app using Delphi?” Yes, really. TMS WEB Core uses Object Pascal to JavaScript converter and creates PWA application which you can run using cell phone web browser. I mean that you are creating the project, compile it and after that you have a folder with your website which you deploy to the web hosting or cloud. Then you open this application from your web browser on your mobile phone and modern browsers detect that it is not a regular website - this is portable web application. It can remove your status bars, remove your main menu, and give a possibility to add an icon to the home screen of your device. One more advantage of course is that PWA application can have access to the platforms and device hardware. Of course, limited, not 100%, even worse than cross-platform. And, as I said, app will have shortcut and can be opened without internet access with limited functionality. It's again PWA technology like application cached your files and knows how to work on the device without internet connection until you don't need to refresh some data from the server.

How does it work? You create Delphi TMS WEB Core project on your machine. You compile it – you will have a folder with HTML5, JavaScript, CSS files. Then you deploy these files to the web server. Then you can open the app using a web browser on the cell phone and the app can have screen shortcut and can start without internet connection. For the first run of course you need internet connection.

Which pros do we have? You can use Delphi IDE for developing progressive web mobile applications using what-you-see-is-what-you-get (WYSIWYG) editor. Later on the next slides I will show you an example how it looks like in the IDE designer and in the real browser. Application is cached to the device and can work offline (in limited mode). If TMS WEB Core components list does not suggest you implement some functionality you can use JavaScript, HTML templates, CSS style files and customize your app whatever you want. TMS WEB Core project supports this possibility. You can use possibilities of Bootstrap and other popular JavaScript frameworks for developing your application. You really don't have to spend a ton of time learning how to work with each platform because it's really one applications with the same UI for different platforms.

Here is an example which I prepared. On the left side you can see how the form can look like in the IDE designer. Of course it's not exactly like it will look in the real life, on production because I added different UI implementation inside CSS and HTML and after I'm running it you can see how it can look like with a pretty good background but the UI looks like in the designer. You just can double click the register button, write the code, communicate with server and it will be converted to JavaScript which again will work with some REST API servers and you will have a real application.

Which cons do we have? I'd like to add a remark that almost all cons are not about TMS WEB Core product. Almost all of them are about PWA limitations at all. The first one is the problems with the distribution to app stores, especially for Apple App Store and this is the most famous distribution channel for the for the users where they search applications. For creating a rich UI and user experience application you will need a good JavaScript/HTML// CSS knowledge. But usually a lot of people start using PWA because they are already using HTML and JavaScript and they know this technology. PWA is a web browser application and it cannot have access to the hardware on the same level like native code can.

Now a couple of words about how you can start with mobile application development using Delphi. I just suggest you to start with this resources. Inside the Delphi GetIt package manager you can find amazing samples of mobile applications, they will explain you how to implement pretty and good-looking forms with different lists, scaling, UI. It has at least six samples. Then you can go to FMX Express. It is a website with a ton of examples and solutions for FireMonkey and I really like this site. For the TMS WEB Core you can explore detailed Developers Guide available after product installation. It's very detailed, with a lot of remarks, explanations how the technology works. And of course you can use Stack Overflow and other popular resources. This is what I can suggest you for the start.

Thank you for the attention. See you!