Building a macOS Hello World Console Application
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.
Contents
- 1 Prerequisites
- 2 Steps
- 2.1 Connect your PC to a Mac
- 2.2 Run the Platform Assistant on the macOS target
- 2.3 Create a connection profile for the Platform Assistant server
- 2.4 Add an SDK for the macOS Target
- 2.5 Create and configure a console application for the macOS target
- 2.6 Write the code
- 2.7 Run the console application on the macOS target
- 2.8 Debug the application
- 3 See Also
Prerequisites
See Setting Up Your Development Environment for macOS.
Steps
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
- 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:
- To install on the target Mac, use
RADPAServerXE4.pkg
. For instructions, see Installing the Platform Assistant on a Mac. - To install on the PC, use
setup_paserver.exe
. For instructions, see Installing the Platform Assistant on Windows.
- To install on the target Mac, use
- Note: paclient.exe, the Platform Assistant Client Application is installed on your development system when you install RAD Studio.
- Open a Terminal window on the Mac.
- Change the directory (
cd
) to the directory that contains the Platform Assistant (PAServer). - Run the Platform Assistant by entering:
./paserver
- 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
- Choose Tools > Options > Environment Options > Connection Profile Manager.
- Click Add. The Create a Connection Profile wizard opens.
- 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.
- 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.
- To determine the IP address of the remote machine, enter either of the following commands:
- 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.
- 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.
- In Remote machine (IP address or Machine name), enter the name or the IP address of the remote machine (the Mac).
- Click OK to close the Connection Profile Manager page.
Add an SDK for the macOS Target
- Choose Tools > Options > Environment Options > SDK Manager.
- Click Add. The Add a New SDK dialog box opens.
- In Select a platform, select the target platform, in this case macOS 64-bit (Intel) or macOS 64-bit (ARM).
- In Select a profile to connect, select the connection profile you previously created.
- 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.
- 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
- Choose File > New > Other. The New Items dialog box appears.
- Select either Delphi Projects or C++Builder Projects and then double-click Console Application.
- 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.
- In the Project Manager, right-click the Target Platforms node, click Add Platform:
- 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:
- Associate an SDK and a connection profile to the macOS target:
- Right-click the macOS platform in the Project Manager to display the following context menu:
- On the context menu, select Properties. The Platform Properties dialog box opens.
- Select in SDK (Software Development Kit) the SDK that you created for this Hello World application.
- In Profile, select the connection profile that you created for this Hello World application.
- Click OK to save the changes.
- Right-click the macOS platform in the Project Manager to display the following context menu:
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:
- For C++ only, add after the other
#include
directives:#include <iostream>
- 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!'); Readln;
- For C++, enter the following code before the line
return 0;
:std::cout << "Hello, World!" << std::endl; std::cin.ignore();
- For Delphi, enter the following statements in the try block (before the except keyword):
- Save and name the application (File > Save).
Run the console application on the macOS target
- Choose Run > Run Without Debugging.
- RAD Studio displays: The project must be compiled before it can be deployed. Continue?. Click Yes.
- 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
- MacOS Application Development
- Working with a Mac and a PC
- Developing Multi-Device Applications
- Connection Profile Manager page in Tools Options
- Create a Connection Profile wizard
- Select Connection Profile dialog box
- SDK Manager page in Tools Options
- paserver, the Platform Assistant Server Application
- FireMonkey Platform Prerequisites
- macOS Man Pages
- macOS Command Line 101