Created
November 19, 2013 16:02
-
-
Save freeonterminate/7547661 to your computer and use it in GitHub Desktop.
Delphi で OS X / Objective-C のランタイムライブラリを呼んでいるサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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