Category
Early last year, I was contacted by Packt Publishing with a request to write a book about Delphi. I was surprised, honored, and a little scared! I know the Delphi community is world-wide but does not have as large a following as other languages so was unsure how much of an audience there would be. Looking at the Delphi books out there, the blog posts, forum discussions, and my own thirst for better understanding of writing for multiple platforms, I began to see a need for a book that catered to people like me, who had worked with Delphi for a long time but were hesitant to climb the learning curve to fully embrace mobile and IoT platforms.
After tossing around ideas for the book with the acquisition editor and a couple of other people from Packt, we settled on the name "Fearless Cross-Platform Development with Delphi" to appeal to programmers that might have similar feelings for moving beyond the comfort zone of writing Windows apps with the VCL. The FireMonkey framework, along with accessing mobile features such as the camera or GPS, adding security, dealing with small, touch-screen devices, all seemed so daunting. Could Delphi really do all that and do it well? How do you write once and deploy to several different devices? Do phones that fit in your pocket really support serious database apps?
I had answered many of these questions for myself already but there were subjects which I had not yet tried out myself, such as Bluetooth and 3D, that I knew needed to be part of this text. The term "cross-platform" isn't relegated to just mobile and IoT devices, it also refers to building Windows services, Linux daemons, and web servers, as these are very different than end-user Windows applications. Yes, there was a lot of ground to cover--and a lot to learn!
Writing a blog or forum post or tweet is pretty simple; it's short and only takes a few minutes--maybe a couple of hours or more for long, detailed blogs. Writing a book is a multi-month commitment. I enjoy writing and even wrote a chapter of a book for a friend of mine back in the 90's (see Power Windows 95) but had never taken on a writing project so large as this. I knew it would take up many evenings and weekends as I couldn't just let my business slide for a year while I devoted myself to this--it had to be a family decision. My wife understood the opportunity and agreed to support me; she was able to work from home due to the pandemic for most of the writing project, so it all worked out.
With enough background to get going, an interest in writing, a new virtual machine set up for testing and development, and support from my family, I decided to pursue this book project!
How do I start?
The first task from Packt Publishing was to create an outline for the entire book. Never having written a whole book before, I was somewhat startled as I hadn't though of everything I was going to write about, let alone create a full outline. This, as I found out later, became a very important task as every chapter I wrote later was checked against this outline to make sure I was covering everything I said I was going to cover. There were topics that I had not yet researched but had read blogs about or seen marketing bullet points from Embarcadero I figured should be included so listed them in the outline; later, when I started researching and writing test programs, I realized some of these topics were much more difficult and time-consuming than I had anticipated. There was also a chapter I realized should've been written later and had to reorganize three of them after I had started--which led to renumbering chapter figures, changing references to GitHub projects, and confusion among the editors clear to the final revision. TIP: If you're going to start a book-writing project, apply good software practices to your writing and do a LOT of up-front research and design before you actually start writing!
The first chapter, I decided, should be a recap of What's New in Delphi over the past few versions. If my target audience is programmers who are using older versions of Delphi to write VCL apps, they may not be aware of things added in recent years. Before I started my subscription with Embarcadero, I would only upgrade every 2 or 3 versions. Like many others, I would only read what was new in the version for which I was installing, often finding out about library additions or IDE enhancements years later while watching a webinar or reading a blog. (Ever have one of those "Hey! How did you do that?" moments?) My goal was to get programmers up-to-speed and as productive as possible and help them with things they may have missed.
Once the reader was familiar with the IDE, the next daunting thing to cover was the great number of ways to start a new project. Instead of just Windows VCL app, DLL, package, or web module, we now also have several ways to start a multi-device application. I tried to write based on questions I had when I first looked at these and it's hard to fully grasp what a particular template will be like by just reading the description and looking at the thumbnail image associated with it. So the second chapter covered these in detail with screenshots and full explanations to help the reader understand how choosing one over another will get them started.
The third chapter explains some of the history of the Object Pascal language that Delphi uses and how enhancements over the years has enabled it to support cross-platform development. There are still programmers that are uncomfortable with generics or anonymous methods or attributes, all important concepts for cross-platform development.
Diving into Cross-Platform
Chapter 4 gets into writing your first cross-platform application, first examining the FireMonkey framework and highlighting many of the differences between it and the VCL and then detailing how to actually get your apps onto other devices such as using the PAServer for Mac and iOS platforms or installing the right SDK driver to talk to Android devices. The downside to writing a chapter like this with explicit instructions and screenshots of setting up device connections is that operating systems and SDKs are upgraded so frequently, there are sections of this chapter that are already obsolete. My hope is that people reading it will get an idea of the steps that need to be taken and use this chapter as a guideline to help them get their own systems set up properly.
The fifth chapter was a mix of old and new techniques. Writing libraries and packages and components has been supported in Delphi since day one but making them work for multiple platforms adds a new twist. It was actually quite interesting to learn how to write components that, while used in the 32-bit Windows IDE, can tell the compiler to include code for other platforms.
I've been surprised when LiveBindings is mentioned in forums or webinars, to hear that many programmers have either never used it or strongly dislike it. Perhaps it's a lack of experience or understanding about this new way of linking data to controls that discourages their use, perhaps it's the LiveBindings designer that can quickly get cluttered--or perhaps they just like to write lots of code! In any case, the sixth chapter was written to explain LiveBindings in great detail, showing how to organize them for easier management and how to write custom methods to suite your own needs. Hopefully, it'll win over some of you!
A book on cross-platform development wouldn't be complete, in my opinion, without showing programmers how to implement styles in their projects. Writing chapter seven on using FireMonkey styles showed how having a good handle in this subject can greatly enhance your apps' visual appeal.
A significant diversion from the topics in the rest of the book, chapter eight focused solely on using 3D graphics. After writing a tutorial app showcasing several different 3D techniques, I explained how to use these built-in components that come with Delphi to write a complete (and hopefully fun) "escape" game that works on your mobile devices.
Back to business in chapter nine, I took a dive deep into two different database products, InterBase and SQLite. I chose these two partly to illustrate how FireDAC handles the differences between them with ease, and also to help the reader understand the capabilities and variety of licenses available. InterBase comes with Delphi so Delphi programmers should have a good understanding of what it is and when they should or should not use it. Additionally, it's similar to Firebird, a popular open-source derivative from InterBase 6.0 that many Delphi programmers use. I compared this with SQLite, a completely free database that is really more of a library that provides database functions than anything--there is no server part--but it's natively available for every platform!
Mobile device capabilities were highlighted in chapter 10. Using the camera, location services, mapping, and sharing data with other applications was a lot of fun. In this chapter, I showed how to build a mobile app called, MyParks, using many of the techniques described in earlier chapters, databases, styles, cross-platform deployment, LiveBindings, and more, and then added mobile capabilities to capture, record, and save park information. (I actually visited over a dozen parks in my area while testing this.) I learned--and explained--how to request access permissions on Android (and why you don't have to on iOS), how to store images in a local database from either the camera or the device's photo library, how to get and map the location, how to display this information nicely on the screen using a TListView
, and how how to share all this with others. This app is revisited several more times in further chapters.
The final part in the section on mobile applications, chapter 11, was one of the most difficult. I had never worked with Bluetooth before and found this to be quite challenging as it behaves differently on different platforms--and sometimes not at all. But I couldn't ignore it, not only because it was in the chapter outline the editors were holding me to but also because Bluetooth is the basis for BLE, or Bluetooth Low-Energy, which is used by all things IoT, a critical part of this book. Researching this was hard as many of the tutorials like to skip right to using IoT, Beacons, and ThingConnect devices which left a lot of questions in my mind until I realized they were all based on Bluetooth. Before the chapter ended, I found a way to tie in a mention of how to install your app on a Raspberry Pi. I felt it was cheating just a little because it requires a version of Android to be working on the Pi first--hopefully there will be a native ARM compiler for these small system-on-chip computers someday.
Servers
Often, instructions about building client and server projects start with the server. After all, you need a server to which a client connects, right? Well, this may be considered a little backwards then but I figured people wanted to learn about mobile programming quickly--and very well may have no need or interest for building their own server. Chapter 12 seems to start over at the beginning with console-based servers but it's the foundation for many other types of servers and introduces an important topic when writing headless applications: logging. Not only are console applications explained in depth for Windows and Linux but Windows Services and Linux Daemons are also covered (Warning! Writing a Linux daemon is not a simple task!).
Chapter 13 moves further along in the server topic by going into great detail about writing web modules for Windows IIS, Windows Apache, and Linux Apache. The examples for these server chapters use the park data collected in prior chapters and stored in InterBase. I have immediately put to use for customer projects, several things learned while writing this chapter. I'll admit that using WebBroker for the examples is not only an old technology but also quite difficult to use for any large and serious web project; but there was just so little documentation for it and it's the only truly free and built-in web-building technology available out-of-the-box for Delphi, so I felt compelled to write about it. There's actually a live example of the sample app from this chapter running on my home server at myparks.net.
Chapter 14 tackled a brand new topic for me: RAD Server! Learning about this amazing product from Embarcadero was eye-opening for me. Initially, the price tag for deploying a solution built on RAD Server to a customer site caused me to ignore it but once I started writing about it and really learning all it could do, I immediately thought of several cases where it would be a great solution. It really does do a lot of the work for you and lets you concentrate on the needs of your specific app. I was so taken with this technology, I devoted a section of the chapter to justify the price--and how it can save you far more in development costs. This is also one of the two places in the book where I took the time to design a diagram that illustrates how RAD server fits into a deployed application suite. And, once again, we modified the MyParks app, this time showing how to use it as a client to access park data from a RAD Server module.
The last chapter of the book brings together many topics discussed earlier and tries to tie it all together with final tips on making sure your app is ready for the real world. Chapter 15 covers security, icons and logos, version information, testing, and makes an attempt to explain how to submit apps to both Apple and Google app stores. I say "attempt" because the policies and procedures are constantly changing and, to be honest, even though I've built cross-platform apps, I admittedly have not yet successfully published an app on either of these platforms; there are many things to check off and I just ran out of time.
Summary
In summary, I'm glad I did it but I'm also glad it's over! Will there be a second edition? Perhaps. We'll see what the reception is for this one. I already know of things I would change and a chapter or two that I would add. I learned a LOT (which was another reason I took this on) and have increased respect for both producers of cross-platform apps and the people at Embarcadero tasked with maintaining a very complex set of tools and libraries to try and support an enormous breadth of application types and devices while continuing to enhance this great integrated development environment I love and use every day.
Long Live Delphi!
Add new comment