Using Mono and Delphi Prism

Abstract: This article describes the capabilities of developing for Mono using Delphi Prism

Introduction

Delphi Prism provides support for compiling code against multiple CLR platforms, including Mono for Linux and for the Mac. If it can be done in Mono, it can be done with Delphi Prism. This article covers the basics of working with Mono and what you can expect when using Delphi Prism.

Delphi Prism produces pure Intermediate Language (IL) code for running on the Common Language Runtime (CLR). Since Mono implements the CLR, Delphi Prism applications will fully support the Mono platform. Therefore, Delphi Prism developers can deploy their applications to anywhere that the Mono platform is present. In as much as the Mono platform supports IL and the CLR, Delphi Prism code will run.

Installing and Running Mono

Hide imageMono is a third-party set of libraries that need to be present for developing and deploying Mono applications. Mono is available for numerous platforms and can be found at The Mono Project. To develop Mono-based projects with Delphi Prism, Mono for Windows should be installed along side Delphi Prism, and Mono-based applications need to be made aware of the specific location of the Mono binaries. Unless specifically deselected, Mono is installed as part of the Delphi Prism installation and is installed by default in the C:\Program Files\Mono-2.0.1 directory.

Delphi Prism supports the full capabilities of the Mono framework on whatever platform it is found. Developers should note that there are differences between the features and capabilities of the Mono platform and those of Microsoft’s .NET implementation on Windows. Generally, developers will need to test their applications very carefully to ensure that resources that they need are available. Thus, if Mono doesn’t support a given call, method or namespace, then code that requires those resources will not run.

Delphi Prism developers are strongly encouraged to use the Mono Migration Analyzer (MoMA) tool to determine how well as a given application built with Mono in mind will run on non-Windows platforms and what specific areas need to be adjusted in order for that application to run properly on Mono.

Because Delphi Prism produces standard, IL-based assemblies, developers can partition code into different binaries, making it easy to share code between Mac, Windows, and Linux versions of an application. Using proper MVC partitioning, the user interface code can be made specific to different operating systems and user interface frameworks and toolkits.

Capabilities and Compatibility

Since Mono is an implementation of the CLR, it differs from the .NET framework. With respect to Mono, .NET can be viewed as Microsoft’s implementation of the CLR on Windows. Mono for Windows exists, but mainly as a supplement to .NET. Mono itself implements large portions of the CLR, mainly on Linus and Mac OS X. However, Mono is not as complete an implementation of the CLR as .NET is, and thus Mono has some limitations in the support it provides for the CLR.

Below is a chart that discusses some of these limitations, and how each framework in Delphi Prism and the CLR are supported by Mono on Linux and the Mac.

Feature

Mono for Linux

Mono for the Mac

Compiler

Since the compiler is itself a managed code binary, it will run on the Mono for Linux framework.

Since the compiler is itself a managed code binary, it will run on the Mono for Mac framework.

Command Line/Server/Daemon Apps

Prism apps of this sort should work just fine with Mono on Linux.

Prism apps of this sort should work just fine with Mono on the Mac

Debugging

Applications meant for deployment on Mono for Linux are best debugged while running on Windows as much as is possible.

Mac OS X applications cannot be run inside Visual Studio, but developers can properly decouple code and then run and debug Model and Controller code on Windows.

dbExpress

dbExpress is bound to Windows and the Windows database clients, and thus applications using dbExpress won’t run on Mono. However, Mono supports ADO.NET, and thus Delphi Prism developers can access data that way.

dbExpress is bound to Windows and the Windows database clients, and thus applications using dbExpress won’t run on Mono. However, Mono supports ADO.NET, and thus Delphi Prism developers can access data that way.

ASP.NET

Delphi Prism applications built for ASP.NET will run on Mono for Linux and Apache utilizing the mod_mono plugin. In addition, Mono on Linux provides the xsp2 executables are available for debugging.

ASP.NET applications built with Delphi Prism should run on Mono for Mac and Apache utilizing the mod_mono plugin.

Winforms is supported on Mono for Linux. Many applications will run without modification, but others will require some developer work to run. See http://tinyurl.com/WinformsToMono

for more information. Developers can also use the Mono Migration Analyzer (MoMA) tool mentioned above to determine how well a given application will run on Mono and what specific areas need to be adjusted.

Mono for the Mac provides support for Winforms, but that support is currently in its early stages and should be considered no better than alpha quality. Developers should also note that a Winforms application will not appear like a “normal” Mac application.

Windows Presentation Foundation (WPF)

WPF is not supported on the Mono for Linux platform.

WPF is not supported on the Mono for Mac platform.

Silverlight

Mono implements a project called “Moonlight” in cooperation with Microsoft and Delphi Prism applications can execute against that framework. It is currently in alpha stage.

Silverlight is officially supported by Microsoft on the Mac OS X platform.

Windows Communication Foundation (WCF)

Mono has a project called Olive that is in its early stages of support for WCF.

Mono has a project called Olive that is in its early stages of support for WCF.

Developing with Delphi Prism for the Mac

Delphi Prism provides specific support for developing for Mac OS X.

The standard user interface framework for Mac OS X is Cocoa. Cocoa is a collection of frameworks, APIs, and accompanying runtimes that make up the development layer of Mac OS X. Mono includes a wrapper around the key classes of Cocoa called Cocoa#. The file containing that wrapper is cocoa-sharp.dll and is part of the Mono framework.

Delphi Prism developers can make use of the Cocoa# framework to provide interaction between Hide imageDelphi Prism classes and user interface files created for Cocoa with Interface Builder. Interface Builder is a user interface design tool included with Mac OS X. Delphi Prism includes templates and support for building applications against the Cocoa# framework. Cocoa utilizes the “Model-View-Controller” method of development. Developers can build a “View” using Interface Builder and then use Delphi Prism to provide the “Model” and “Controller” portions of an application.

Delphi Prism will also automatically generate all the necessary “glue” code for the files generated by Interface Builder. For example, if a button is added to the interface using Interface Builder, Prism will see that and generate the proper code in the partial class in the associated file in Delphi Prism. These features make for a very powerful and capable development experience on the Mac when using Delphi Prism.

Note, as well, that while it is possible to use Delphi Prism to develop .NET Winforms applications that will run on OS X, such applications will lack the native ‘look and feel’ of applications created with Apple’s Cocoa UI frameworks.

In addition, Delphi Prism provides “MacPack” -- package deployment for Mac applications, which wraps up all the necessary files for deployment and puts them in a shared network location for easy execution on the Mac machine.

Probably the simplest way to develop Delphi Prism applications for OS X is to install Windows in a virtual machine such as Parallels or VMWare Fusion on a Mac computer, and ensure that a shared file location on the Mac is visible to the Windows virtual machine. Or, developers can place application inside of a network share that resides on a Mac machine, and then run the application from the Mac. Developers should remember that the resulting application will, in fact, be a Mac OSX application and thus won’t run on Windows as Cocoa is not available on Windows.

Conclusion

Delphi Prism provides full support for developing on Mono – including code generation and deployment assistance for the Mac. While that support is limited to the capabilities of Mono itself, overall, Delphi Prism is an excellent tool for supporting Mono development. And as Mono’s capabilities and support for the CLR grows from its already considerable capabilities, so will Delphi Prism’s support for it.