Macos 如何在Delphi XE4中向Mac OS Finder添加菜单项

Macos 如何在Delphi XE4中向Mac OS Finder添加菜单项,macos,delphi,service,delphi-xe4,Macos,Delphi,Service,Delphi Xe4,我试过这个例子。然而,这个例子不适用于XE4(或者我做错了什么) 我的代码: 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

我试过这个例子。然而,这个例子不适用于XE4(或者我做错了什么)

我的代码:

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>

CFBundleName
你好世界
CbundleDisplayName
你好世界
CbundleIdentifier
你好世界
循环流化床锅炉
1.0.0
CbundlePackageType
应用
CFBundleSignature
????
CbundleAllowMixedLocalizations
对
Cbundlexecutable
你好世界
NShighResolutionable
真的
LSApplicationCategoryType
public.app-category.utilities
CbundleShortVersionString
0
循环流化床锅炉
delphi_projectcns.icns
NSS服务
NSKeyEquivalent
违约
E
NSMenuItem
违约
欢迎我
NSMessage
简单消息
NSPortName
你好世界
NSSENDTYPE
NSStringPboardType
NSReturnTypes
NSStringPboardType
当在Mac OS上运行时,应用程序显示表单,但服务菜单不显示新项,如info.plist中所述


如何显示菜单项?

您调试过吗?
applicationdFinishLaunching
是否执行?是的,此方法已执行。并且
provider.objId
有效?您的意思是什么?objID返回一些非nil值。如何检查?另一方面,我试图将IMessageProvider声明为NSObject的接口。因此,TMessageProvider被继承(TOCLocal,IObjectiveC),函数getObjectiveClass被重写(结果:=TypeInfo(IMessageProvider))。不幸的是,结果是一样的。