Cocoa Internals/OS Versions

From Lazarus wiki
Revision as of 05:57, 7 July 2018 by Skalogryz (talk | contribs) (starting the page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The page coverages on issues of (backwards) compatibility and API deprecation across different macOS version

(Plain) Functions

It's possible that a new feature requires a function that has been introduced in a later version of macOS. In this case a straight use of the function would cause a load-time fail on earlier versions of OSX.

In order to prevent that, a dynamic loading of the function needs to be used.

uses ... 
  dl, dynlibs;
...
  p := GetProcedureAddress(TLibHandle(RTLD_DEFAULT), 'CGDisplayCreateImage');

The following needs to be taken into consideration:

  • the use of RTLD_DEFAULT - searches for the function name across all loaded libraries. The system library would like be loaded by that time. However, if not the actual library name needs to be loaded. (unlike Linux, macOS doesn't require the full library path to be specified)
  • if the symbol is not present, then the code should handle it gracefully (instead of calling to unspecified function)