Show Badge on Application Icon in Dock
From Free Pascal wiki
This article applies to macOS only.
See also: Multiplatform Programming Guide
│ English (en) │
Example code
unit Unit1;
{$mode objfpc}{$H+}
{$modeswitch objectivec2}
interface
uses
Classes, SysUtils, Forms, Dialogs, StdCtrls,
CocoaAll;
type
{ TForm1 }
TForm1 = Class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormActivate(Sender: TObject);
begin
// NSApplication.sharedApplication
// - Returns the application instance, creating it if it doesn’t exist yet.
// NSApp
// - The global variable for the shared application instance.
NSApp := NSApplication.sharedApplication;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// Display badge text on the dock tile (icon)
NSApp.dockTile.setBadgeLabel(NSStr('1'));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
// Remove badge text from the dock tile (icon)
NSApp.dockTile.setBadgeLabel(NSStr(''));
end;
end.