Cocoa Interface

This is an old revision of Cocoa Interface, edited by Skalogryz at . The current revision is 52007.

/* Compiling */

This article applies to macOS only.

See also: Multiplatform Programming Guide

This article applies to iOS only.

See also: Multiplatform Programming Guide

Other Interfaces

Platform specific Tips

Interface Development Articles

Cocoa bindings

This interface uses the native support in Free Pascal for direct communication with Objective-C was added through the Objective Pascal dialect.

Compiling

Use FPC3.0.4a

For Mojave 10.14 and later you should be installing fpc 3.0.4a available at the official site.

Prepare your Lazarus project for using Cocoa

You may need to set the Target to the 64bit processor and select the Cocoa Widget set:

Error ATSUFindFontFromName

if you're getting an error

carbonproc.pp(563,13) Error: Identifier not found "ATSUFindFontFromName"

when compiling a project for macOS using FPC 3.0.4 you need:

  • You either set the target in Project options (by switching it from default to i386)
  • or if you compiling from command-line (i.e building an IDE) set up the following parameter to make command
CPU_TARGET=i386

Cocoa FAQ

TButton looks too small!

If you design a button in another widgetset with Autosize=Off it might happen that the button looks too small in Cocoa, and a number of people complained about this, such as in these BTS reports: https://bugs.freepascal.org/view.php?id=31185.

If you don't care about the button size, just set AutoSize=True. If you want to have a custom width for the button, but wants to allow the LCL to choose the right Height so that the button will look good in Cocoa, then the solution in this case is to set the following properties in the Object Inspector:

Overlapping Widgets

Lazarus allows you to set the depth of different widgets, such that when two widgets overlap, the "closer" object blocks the view of the more "distant" object. You can do this at design time (right-click on object and click "Z-order") or at run time with functions like "BringToFront" and "SendToBack". Be aware that this may not always work with Cocoa. This is a 'feature' of Cocoa, as clipping is optimized for performance. Therefore, if you plan to compile your projects for Cocoa it is a good strategy to avoid overlapping widgets or to place them on different panels to provide explicit control of Z-order. For more details https://bugs.freepascal.org/view.php?id=32991.

Roadmap

Located here: Roadmap#Status_of_features_on_each_widgetset