Skip to content

Instantly share code, notes, and snippets.

@freeonterminate
Created November 19, 2013 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save freeonterminate/7547661 to your computer and use it in GitHub Desktop.
Save freeonterminate/7547661 to your computer and use it in GitHub Desktop.
Delphi で OS X / Objective-C のランタイムライブラリを呼んでいるサンプル
unit uNSAppSample;
interface
implementation
{$IFDEF MACOS}
uses
// Delphi の RTL
System.SysUtils, System.Generics.Collections,
// FireMonkey の Unit
FMX.Dialogs,
// MacOS X / Objective-C の RTL
Macapi.ObjectiveC, Macapi.AppKit;
type
// MacOS X のインターフェース NSApplicationDelegate を継承している!
TAppDelegate = class(TOCLocal, NSApplicationDelegate)
public
procedure applicationWillTerminate(Notification: Pointer); cdecl;
procedure applicationDidFinishLaunching(Notification: Pointer); cdecl;
end;
// Application 終了時に呼ばれる
procedure TAppDelegate.applicationWillTerminate(Notification: Pointer);
begin
ShowMessage('アプリケーションが終了するよ!!');
end;
// Application 起動時に呼ばれる
procedure TAppDelegate.applicationDidFinishLaunching(
Notification: Pointer);
begin
ShowMessage('アプリケーションの初期化処理が終わるよ!!');
end;
// Initialization から呼ぶ初期化部
procedure Init;
var
NSApp: NSApplication;
begin
// NSApplication の実体を取得
NSApp := TNSApplication.wrap(TNSApplication.OCClass.SharedApplication);
// NSApplication のメソッドを呼ぶ!
// NSApplicationDelegate を実装した TAppDelegate のインスタンスを
// そのまま渡せる!
NSApp.setDelegate(TAppDelegate.Create);
end;
initialization
begin
Init;
end;
finalization
begin
end;
{$ENDIF}
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment