Building a macOS Hello World Console Application

From RAD Studio
Jump to: navigation, search

Go Up to MacOS Application Development

This "Hello World" tutorial demonstrates the essential steps for creating a multi-device application in Delphi. This application targets the macOS platform (the Mac), a console window, an event, and displays a dialog in response to a user action.


See Setting Up Your Development Environment for macOS.


To create the macOS "Hello World" console application:

Connect your PC to a Mac

See Working with a Mac and a PC.

Run the Platform Assistant on the macOS target

  1. The Platform Assistant needs to be running on both the development PC and the target Mac:
    • If the Platform Assistant is already installed on the PC and the Mac, go to the next step.
    • If the Platform Assistant is not yet installed on the PC or Mac, install the Platform Assistant on the target machine. The installer is available to run on the PC or Mac, as follows:
    Note: paclient.exe, the Platform Assistant Client Application is installed on your development system when you install RAD Studio.
  2. Open a Terminal window on the Mac.
  3. Change the directory (cd) to the directory that contains the Platform Assistant (PAServer).
  4. Run the Platform Assistant by entering:
  5. When you are prompted to set a password, enter an optional password string. This is the password that will be required from any connection profile connecting to this instance of the Platform Assistant. To set no password, press Enter.
The Platform Assistant displays a sign-on message and its command prompt (>).

Create a connection profile for the Platform Assistant server

  1. Choose Tools > Options > Environment Options > Connection Profile Manager.
  2. Click Add. The Create a Connection Profile wizard opens.
  3. On the first page of the wizard (Profile information):
    • In Profile name, enter a name for the connection profile.
    • In Platform, select the platform where the Platform Assistant server is running, in this case macOS 64-bit (Intel) or macOS 64-bit (ARM).
    • Click Next.
  4. On the second page of the wizard (Remote machine information):
    • In Remote machine (IP address or Machine name), enter the name or the IP address of the remote machine (the Mac).
      • To determine the IP address of the remote machine, enter either of the following commands:
        • i on the PAServer console on the Mac.
        • ifconfig on the Mac Terminal window.
    • Leave Port number as the default, 64211.
    • In the Password field, enter the optional password string that was set when you started the Platform Assistant that you are connecting to. To search for a password file (*.passfile, created using paserver and containing an encrypted password for sharing with other users), click the ellipsis (...). If no password has been set for the Platform Assistant, leave this field blank.
    • Click Test Connection.
      • If the connection fails, verify the target machine name or IP address (try pinging them on the cmd window), and then ensure that the Platform Assistant is installed and running on the target machine.
      • If the connection succeeds (or fails), click Next.
    Note: You can create a connection profile even if the connection to the target has not yet succeeded. However, a valid connection profile is necessary at several critical times during macOS application development, that is, running, debugging, and deploying.
  5. Click OK to close the Connection Profile Manager page.

Add an SDK for the macOS Target

  1. Choose Tools > Options > Environment Options > SDK Manager.
  2. Click Add. The Add a New SDK dialog box opens.
  3. In Select a platform, select the target platform, in this case macOS 64-bit (Intel) or macOS 64-bit (ARM).
  4. In Select a profile to connect, select the connection profile you previously created.
  5. In Select an SDK version, select Command Line Tools.
    The Command Line Tools SDK provides the basic headers and libraries for building a macOS application, enough for your Hello World application. Any other SDK from the list would do as well, since all of them provide the libraries from the Command Line Tools SDK as well.
    Note: The list of available SDKs is retrieved from your macOS system, using the connection profile you selected during the previous step. If the combo box list is empty or is missing a specific SDK, see Adding a macOS or iOS SDK for troubleshooting.
  6. Click OK to close the SDK Manager page.

The files (headers and libraries) of the specified SDK will be pulled from the Mac to the development PC. To include additional libraries or frameworks see Add Remote Path Item or Edit Remote Path Item.

Create and configure a console application for the macOS target

  1. Choose File > New > Other. The New Items dialog box appears.
  2. Select either Delphi Projects or C++Builder Projects and then double-click Console Application.
  3. In the New Console Application (C++) dialog box, make sure that Console application is checked, Target Framework is set to None, and Multi-threaded is unchecked. Then click OK.
  4. In the Project Manager, right-click the Target Platforms node, click Add Platform:
  5. On the Select Platform selection box, select macOS 64-bit (Intel) or macOS 64-bit (ARM), enable the Make the selected platform active checkbox, and click OK:
    Select Platform Options.png
  6. Associate an SDK and a connection profile to the macOS target:
    1. Right-click the macOS platform in the Project Manager to display the following context menu:
      Platform Properties Menu.png
      On the context menu, select Properties. The Platform Properties dialog box opens.
      Platform Properties Box.png
    2. Select in SDK (Software Development Kit) the SDK that you created for this Hello World application.
    3. In Profile, select the connection profile that you created for this Hello World application.
    4. Click OK to save the changes.

The profile name is now displayed next to the macOS platform in the Project Manager. The SDK name is displayed as well if your application is C++.

Write the code

In the Code Editor modify the code generated from the template:

  1. For C++ only, add after the other #include directives:
    #include <iostream>
  2. Add the code to say hello and wait for the Enter key.
    • For Delphi, enter the following statements in the try block (before the except keyword):
      Writeln('Hello, World!');
    • For C++, enter the following code before the line return 0;:
      std::cout << "Hello, World!" << std::endl;
  3. Save and name the application (File > Save).

Run the console application on the macOS target

  1. Choose Run > Run Without Debugging.
  2. RAD Studio displays: The project must be compiled before it can be deployed. Continue?. Click Yes.
  3. On the target machine, the "Hello, World!" message is displayed at the Platform Assistant prompt (after messages from the debugger). Press the ENTER key. After your console application terminates, the Platform Assistant server redisplays its command prompt (>).

Debug the application

To debug your application in the IDE, use any of the standard Run commands:

  • Run > Run (F9)
  • Run > Step Over (F8)
  • Run > Trace Into (F7)

You can also use the Load Process or the Attach to Process command to start the debugger.

All of these commands:

  • Transfer the required files to the target machine, based on the current assigned profile.
  • Run the application in debug mode.

Using the integrated debugger in the IDE to debug a macOS application is very similar to using the integrated debugger to debug a native Win32 application.

If you run your application using a Run command that starts the debugger (such as Run > Run or Run > Step Over or Run > Trace Into), you might be prompted to enter the root password for the Mac in order to give access to the debugger.

See Also