我试过这个question的例子。但是,示例不适用于xe 4(或者我做错了)。
我的代码:
unit uHelloWorld;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
Macapi.ObjectiveC, Macapi.AppKit, System.Variants, FMX.Types, FMX.Controls,
FMX.Forms, FMX.Dialogs, FMx.Platform.mac, System.TypInfo, FMX.StdCtrls,
Macapi.CocoaTypes;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TNSApplicationDelegate2 = class(TOCLocal, NSApplicationDelegate)
procedure applicationDidFinishLaunching(Notification : Pointer); cdecl;
procedure applicationWillTerminate(Notification : Pointer); cdecl;
end;
IMessageProvider = interface(IObjectiveC)['{1EA9319A-8F99-4445-B435-48D5E73876FA}']
procedure simpleMessage(pBoard: Pointer; userData: Pointer; error: PPointer); cdecl;
end;
TMessageProvider = class(TOCLocal, IMessageProvider)
public
procedure simpleMessage(pBoard: Pointer; userData: Pointer; error: PPointer); cdecl;
property ObjId: Pointer read GetObjectID;
end;
var
Form1: TForm1;
delegate : TNSApplicationDelegate2;
implementation
{$R *.fmx}
procedure TForm1.FormCreate(Sender: TObject);
begin
Delegate := TNSApplicationDelegate2.Create();
TNSApplication.Wrap(TNSApplication.OCClass.sharedApplication).setDelegate(delegate)
end;
procedure TNSApplicationDelegate2.applicationDidFinishLaunching(Notification : Pointer); cdecl;
var
app : NSApplication;
provider : TMessageProvider;
begin
try
app := TNSApplication.Wrap(TNSApplication.OCClass.sharedApplication);
provider := TMessageProvider.Create();
app.setServicesProvider(provider.ObjId);
finally
end
end;
procedure TNSApplicationDelegate2.applicationWillTerminate(Notification : Pointer); cdecl;
begin
Application.Free();
Application := nil
end;
procedure TMessageProvider.simpleMessage(pBoard, userData: Pointer; error: PPointer);
begin
ShowMessage('Hello World from Delphi XE4');
end;
end.
的Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>HelloWorld</string>
<key>CFBundleDisplayName</key>
<string>HelloWorld</string>
<key>CFBundleIdentifier</key>
<string>HelloWorld</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleAllowMixedLocalizations</key>
<string>YES</string>
<key>CFBundleExecutable</key>
<string>HelloWorld</string>
<key>NSHighResolutionCapable</key>
<string>true</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>CFBundleShortVersionString</key>
<string>0.0</string>
<key>CFBundleIconFile</key>
<string>delphi_PROJECTICNS.icns</string>
<key>NSServices</key>
<array>
<dict>
<key>NSKeyEquivalent</key>
<dict>
<key>default</key>
<string>E</string>
</dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Welcome Me</string>
</dict>
<key>NSMessage</key>
<string>simpleMessage</string>
<key>NSPortName</key>
<string>HelloWorld</string>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
</array>
<key>NSReturnTypes</key>
<array>
<string>NSStringPboardType</string>
</array>
</dict>
</array>
</dict>
</plist>
在Mac OS应用程序上运行时显示表单,但服务菜单保留没有新项目,这在info.plist中有描述。?
如何显示菜单项?