Targeting multiple platforms

by Tim Anderson

Delphi and C++Builder XE3 are designed for cross-platform development. Find out how they achieve it.

HardCopy Issue: 59 | Published: February 1, 2013

The pressure for cross-platform development has never been greater. Windows remains important, but in scenarios other than tightly controlled corporate environments it is not enough; and even there the trend towards mobile and ‘bring your own device’, where employees can use their own computers, tablets and smartphones, means demand for non-Windows clients. Indeed the truth is that Windows is now running on a minority of client devices, with a larger share going to Android and Apple iOS devices.

This makes cross-platform development tools increasingly attractive. Single-platform tools are still important of course, and allocating dedicated development teams to each target platform may be the best approach for organisations with sufficient resources, although maintaining consistency between clients under such a regime is a problem. On the other hand, maximising the amount of shared code makes sense both for quality and economy, and there is an obvious appeal for tools which can target multiple platforms.

Impressed by 64-bit support

Anthony West is a developer at The Analytical Group which makes Windows software such as WinCross for statistical analysis. He also has his own small software company. Products are built using C++Builder, and he has been testing C++Builder XE3 for some time.

The big feature for him is 64-bit support: “WinCross 10 has the potential to open up some sizeable databases. We’ve had occasions when we get close to 2GB of memory, and 32-bit dies at around 1.8GB. 64-bit gives us the ability to let our customers work with much larger databases.”

How is code compatibility between the C++Builder XE3 and earlier versions? He told us that there were some issues towards the beginning of beta testing, but most are resolved. “About 75 per cent of my applications are already compiling into 64-bit, and the ones that aren’t are just some minor issues.”

West is looking with interest at FireMonkey for cross-platform work in “new projects, and possibly a couple of existing ones. I have some customers asking for Macintosh versions. I’ve already tried messing around with FireMonkey. It is quite different from the VCL with a bit of a learning curve, but yes, I do have plans to do cross-platform development with FireMonkey.”

What does he think of the new release overall? “I’m currently using XE2 for my main products, and the XE3 release is pretty solid for 32-bit applications to move over. But it’s the 64-bit that is really exciting. It’s brand new and a huge undertaking, and I’m impressed that they’ve pulled it together. There are some issues, but I’m a programmer myself, and it’s very difficult not to have issues in a first release of another version.”

Should that be an HTML tool, using Adobe PhoneGap or similar to create native executables on each platform? The debate continues: in some cases this is an ideal solution; in others, the performance of native code and its ability to access device features makes it a better choice.

With its latest set of tools, Embarcadero is supporting both approaches. The centrepiece of its RAD Studio product is Delphi, long the favourite choice of canny Windows developers but now repositioned as a cross-platform development tool. Cross platform development was introduced in RAD Studio XE2 with Mac OS X support, and iOS in a rough and ready form using the open source Free Pascal compiler.

The recently released RAD Studio XE3 supports Windows and OS X out of the box. Support for Apple iOS and Google Android is coming in an add-on pack – iOS in the first half of 2013 and Android to follow by the end of the year. The Android add-on will generate native code rather than Java. The mobile add-on will not be free but Embarcadero says it will be low-cost and included automatically for customers with Software Assurance. No announcement has been made as regards to Windows Phone 8.

Although this could be viewed as a step back from RAD Studio XE2, which already targets iOS, the reason for the delay is the big changes to the developer tools architecture used by the latest C++Builder and future versions of Delphi, starting with the iOS release. This new architecture is based on a language engine which forms a front-end to the open source LVVM compiler. Much of Embarcadero’s effort has been to make the property-method-event programming model used by Delphi and C++Builder work correctly with LVVM.

There are several advantages to LVVM, including the ability to generate code for both Intel and ARM processors. Another aspect is CLANG, the LVVM C/C++ compiler, which provides 64-bit and C++ 11 support. LVVM is used by Apple for its own OS X and iOS development tools.

Note that currently it is only the 64-bit C++Builder that uses the new compiler. The 32-bit compiler is a minor upgrade of the existing one, making it good for compatibility but inconvenient if you need to build the same application in both 32-bit and 64-bit versions.


FireMonkey versus VCL

A longstanding issue for cross-platform development using Delphi and C++Builder is that the VCL (Visual Component Library) is highly Windows-specific. A decade ago, when the team built a version of Delphi for Linux called Kylix, it did create CLX (Component Library for Cross-Platform). However Kylix never caught on and so it was abandoned.

Targeting mobiles with HTML5 Builder

Also part of RAD Studio XE3 is Embarcadero’s HTML5 Builder, the latest version of the product previously called PHP Builder.

HTML5 Builder has four project types: Client Mobile, Client Web, Server Mobile, and Server Web. The ‘Server’ projects are the most complete and includes PHP code that runs on the server. You can still compile the Mobile project as an app, or deploy as a browser-based mobile app if you prefer. By contrast, a Client project is essentially a JavaScript project which may run standalone, although you can still link it to remote data or Web services.

HTML5 Builder has its own IDE which is to some extent inspired by Delphi (and built with it). This is a visual tool allowing you to drag controls and components onto a form, and double-click to open an event handler. One convenient feature is the installation of its own instance of Apache so that PHP debugging is seamless.

Database components are included and you can use Delphi-like Database, Query and Datasource components and bind to visual controls such as combo boxes and lists. There are also DataSnap client components for connecting to Embarcadero middleware.

The deployment wizard prepares your project for installation on a mobile device. The final stage includes a link to Adobe’s PhoneGap Build service which lets you compile a mobile app using a cloud service. This is a commercial service that requires a separate PhoneGap account. The advantage is that you do not need to have the various mobile SDKs installed locally, or to develop on a Mac for iOS deployment. Alternatively, you can install the required SDKs and package the app locally.

The solution today is a framework called FireMonkey which was designed for cross-platform from the outset. This is an abstraction layer which provides visual controls such as buttons, menus, pickers, list boxes and grids for all the platforms it supports. FireMonkey also supports 3D applications with lighting, textures and animation, and the framework takes advantage of hardware acceleration if available.

FireMonkey includes familiar controls and components including data controls like TDataSource and TClientDataSet, but it is not compatible with the VCL and there are many differences. FireMonkey controls are predominantly custom-drawn rather than rendered using native controls but the framework supports both methods, as Embarcadero Senior VP Michael Swindell explains: “It’s a hybrid approach. If it is a simple control like a button, it is simple for us to draw and style. If it is a control that is more complex and very important to that device, like the spinning picker wheels in an iOS device, then we use native controls.”

While the VCL is still supported and will continue as a Windows framework, FireMonkey is the future focus and is required for cross-platform development.


Going cross-platform

Although RAD Studio is a cross-platform tool, there are no immediate plans to have the IDE itself run outside Windows, as Swindell told me: “This is a Windows-only tool but the vast majority of developers that use this are running this on Macs, inside of VMware Fusion or Parallels. That allows you to target Windows, Mac, and when available iOS and Android, on the same machine.”

RAD Studio XE3 Mac development setup

A typical Mac development setup with RAD Studio XE3 running inside a Windows virtual machine under OS X.

You can also run RAD Studio on a separate PC and connect to a Mac over the network. In both cases, you need to install a utility called Platform Assistant (paserver) on the target Mac. This has a dependency on the Java runtime which the setup will download and install if needed. Once installed, you run paserver from a terminal window and optionally assign a password, noting the port on which it is running. On the Mac you also need the Xcode development tools and the Xcode command line tools (a separate download from Apple). You can then create a remote profile that specifies the Mac where paserver is running. The remote profile editor lets you pull the necessary library files from the Mac onto the PC so that the compiler can find them.

Once everything is set up, you can run the project in Windows and see it automatically deployed and opened on the Mac. You can set breakpoints in the code in C++Builder XE3 (or Delphi) and debug the application as if it were running locally. When it comes, Android and iOS support will work in a similar way.

The key advantage is what Delphi and C++Builder have always offered: rapid application development but with the performance and the flexibility of true native code.

Find Out More

For help finding the right tools for your cross-platform development projects, call 01364 65400, email or visit the Grey Matter website.