Show: Delphi C++
Display Preferences

Mac OS X Application Development

From RAD Studio XE2
Jump to: navigation, search

Go Up to Cross-Platform Applications Index


You can use RAD Studio to create Mac OS X apps. From the hardware point of view, you need a Mac machine connected with the development computer (where RAD Studio is installed) through LAN. For details, see Connecting Your PC to a Mac.

The Delphi compiler for Mac OS X is DCCOSX.EXE.

The C++ compiler for Mac OS X is BCCOSX.EXE. The C++ linker for Mac OS X is XLINK.EXE.

Contents

Setting Up Your Cross-Platform Development Environment for Mac OS X

  • Platform Assistant: On the Mac, install and run the Platform Assistant (see Installing and Running the Platform Assistant on the Target Platform).
  • Remote Profile: In the IDE, create and assign a remote profile. (A remote profile is a group of settings that can be easily reused; see Creating a Remote Profile on the Development PC.)
  • Target Platform: In the IDE, set the target platform. When you create a Delphi or C++Builder application, RAD Studio sets the default Win32 as the target platform. To change the target platform to OS X, right-click the Target Platforms node in the Project Manager, click Add Platform, and select OS X. The OS X option is unavailable if the application uses VCL (VCL does not support OS X).
  • Physical Connection: Ensure that RAD Studio can connect with the target Mac; click Test Connection in the Remote Profiles panel.
    • However, if the OS X app does not have an assigned remote profile, the IDE displays the following message:
      A remote profile is required for this operation but has not been assigned.
      Would you like to assign or create a profile now?
      Then the IDE guides you through the necessary steps in creating a remote profile. On the Select Remote Profile dialog, you can create (Add) a remote profile or assign an existing profile to your project.
    • For C++, when you create a remote profile for OS X, and when you reach the C++ directory information page of the Create a Remote Profile wizard, make sure that you enable Use this profile with C++ projects before you click Finish. Then, after you click OK to close the Select Remote Profile dialog box, the Update local file cache operation runs automatically, so that the necessary C++ headers and libraries are copied locally for compiling and linking.

Acquiring the Required Apple IDs

Developing and Testing of OS X and iOS Apps and Self-Distribution of OS X Apps: Developing, testing and self-distribution of OS X apps does not require you to either register or join the Apple Developer Program. Although you need to obtain an Apple ID in order to download the XCode IDE from the App Store, neither Xcode nor your computer need any form of registration.
Likewise, iOS apps can be developed and tested on the simulator without having to register for the iOS Developer Program but, to test on a device, you need to join the iOS Developer Program.
You do not need to join either the iOS or the Mac Developer Programs unless you want to test iOS apps on a device or distribute your apps via the appropriate App Store. However, joining one or both of the developer programs entitles you to access a wealth of developer resources otherwise unavailable.

You might need several IDs, available from and subject to change by Apple Computers, as follows:

Note: At XE2, only Delphi FireMonkey applications can be created for iOS. For more information, see FireMonkey_Development_Setup_for_iOS.

The developer programs for Mac and for iOS provide you with the tools you need (such as Xcode and the SDK), online documentation, and support. Separate programs are available for individuals, companies, and universities, and registration for the group programs costs less per person than for an individual developer.

Sandboxing Required for OS X Apps

Sandboxing restricts access to system resources and is one way that Apple ensures that apps are safe and do not contain any malware.

On the Mac, you need to create a ProjectName.entitlements file and place it in the application bundle, codesign the bundle, package the bundle, and submit it to Apple. Here are the elements you need, and the relevant information from Apple:

Codesigning and Building Your Mac Application on the Mac

These steps are required if you want to submit your application to the Mac AppStore.

Notes:
  • Ensure that you obtain a distribution certificate for submitting apps to the Mac AppStore from http://developer.apple.com/certificates.
  • You will need an Apple Developer Account to do this.
  • Ensure that the certificate is installed in your Keychain (double-click the .cer file in the Finder).
  • You will need an entitlements.xml file for Mac sandboxing.
  1. Build your application in the IDE and deploy it to Mac OS X (Snow Leopard or Lion).
  2. Open a terminal window on the Mac.
  3. Switch to the paserver's scratch-dir, for example:
    Applications/Embarcadero/PAServer/scratch-dir/machinename-profilename/
  4. Run the following commands:
Codesign your application:
sudo codesign -f -v -s "Mac Developer: FirstName LastName" "AppName.app" 
Create an installer package:
sudo productbuild --component "AppName.app" /Applications --sign "Mac Developer: FirstName LastName" --product "AppName.app/Contents/info.plist" AppName.pkg

Using Frameworks in Mac Apps

Delphi RTL

Some RTL units that provide basic functionality are common for Mac and Windows, such as System.pas or System.SysUtils.pas.

A number of RTL units are Mac-only (see Mac Objective-C Frameworks). These units are prefixed with the Macapi or Posix unit scope.

FireMonkey

The FireMonkey framework is ideal for the Mac OS X target platform, and it also supports both Win32 and Win64. See FireMonkey Platform Prerequisites.

VCL (not available for Mac)

The VCL is available only on Windows (32-bit or 64-bit).

Mac C RTL (for C/C++ Development)

BCCOSX.EXE uses header files from several locations for compilation.

The C RTL is distributed in two locations:

Include Path Type

Path

Description

standard

$(BDS)\include\osx\crtl

This directory contains C/C++ RTL header files (.h) provided by RAD Studio. Some of these files include C/C++ header files from $(SYSROOT)\usr\include. For more information see OS X C RTL.

remote

$(SYSROOT)\usr\include

This directory contains C/C++ RTL Mac OS X header files cached on Windows.

For compilation, RAD Studio requires header files that reside on the Mac in the /usr/include directory. If you do not have such a directory on your Mac, then you must install Xcode. Obtaining Xcode is described in Connecting Your PC to a Mac. With the help of PAServer.exe, the Platform Assistant server, RAD Studio automatically copies the header files from Mac to Windows (from /usr/include to $(SYSROOT)\usr\include).

Most of the Mac OS X C RTL is standard, and nonstandard characters are not supported.

Mac C Frameworks (for C/C++ Development)

Mac OS X frameworks provide various useful functions for writing platform-specific software. Some frameworks are C-based and can be included in a RAD Studio C++Builder project. Some frameworks are Objective-C-based (such as Foundation) and can be used only through Delphi interfaces (see the following section).

In order to include a Mac C framework in a RAD Studio project, you must edit the remote profile that you use. Open the Remote Profiles panel and click the Add a new path item button from the right hand side. In the Add Remote Path Item or Edit Remote Path Item dialog, specify the following:

  • Framework remote path (example: /System/Library/Frameworks)
  • Framework name (example: CoreFoundation)

For more information, see --framework and OpenGL Multicolor Tetrahedron (C++).

Mac Objective-C Frameworks (Macapi)

The RTL contains a number of units that provide Delphi interfaces to Mac frameworks written in Objective-C. These units are scoped with Macapi (from Mac API) and typically located in the /source directory of your product installation:

  • Macapi.AppKit
  • Macapi.CocoaTypes
  • Macapi.Consts
  • Macapi.CoreFoundation
  • Macapi.CoreGraphics
  • Macapi.CoreServices
  • Macapi.CoreText
  • Macapi.Foundation
  • Macapi.ImageIO
  • Macapi.Mach
  • Macapi.ObjCRuntime
  • Macapi.ObjectiveC
  • Macapi.OCMarshal
  • Macapi.OpenGL
  • Macapi.QuartzCore
  • Macapi.Security
  • Macapi.SystemConfiguration

The FireMonkey framework relies on some of these units.

For help on these API, see the Apple documentation at http://developer.apple.com/library/mac/navigation/#section=Resource%20Types&topic=Reference

Exception Handling

System.SysUtils contains a number of exception classes that represent non-language/hardware exceptions. These exception classes derive from EExternal. The following exception categories are covered:

  • Floating-point exceptions
  • Integer divide exceptions
  • CTRL+C, CTRL+BREAK
  • Privileged instruction violations
  • Memory access violations

On the Mac, most of the EExternal exceptions originate as Mach exceptions. The only ones that do not originate as Mach exceptions are CTRL+C (EControlC) and CTRL+BREAK (EQuit).

If you use assembly routines, then see PC-Mapped Exceptions, Unwinding Assembly Routines.

Processing of Mach Exceptions

For Mach exceptions, the RTL from System.SysUtils creates a thread that listens for exception notifications from the operating system. You just have to include in your code the System.SysUtils unit. When the listening thread receives a Mach exception notification, it transforms the Mach exception into the corresponding Pascal language exception derived from EExternal, as appropriate, and raises/throws the Pascal exception to the user thread that caused the original Mach exception.

If you want to directly work with Mach exceptions, then be aware that, by including System.SysUtils, a dedicated thread is started for listening Mach exceptions. You can investigate the System.Internal.MachExceptions.pas source to make sure you do not interfere with the RTL.

CTRL+C and CTRL+BREAK

For CTRL+C and CTRL+BREAK, the application installs signal handlers. (OS X does not create Mach exceptions for CTRL+C and CTRL+BREAK.)

The SIGINT and SIGQUIT handlers are in conformity with the standards that define the way shell applications must treat CTRL+C and CTRL+BREAK.

We strongly recommend that you do not override the SIGINT and SIGQUIT handlers. However, if you do this, you do not receive EControlC and EQuit exceptions.

Icons for Your OS X Apps

On the Mac, you typically need a .ico file (icon file) to represent your app in the user interface. Personality-specific .ico files are provided for your use:

  • delphi_PROJECTICON.ico
  • cbuilder_PROJECTICON.ico

These .ico files are available in the /bin directory of your product installation.

Xcode Required for FireMonkey iOS Apps

Mac OS X Topics

See Also

Code Examples

Personal tools
Previous Versions
In other languages