I'm working on Delphi XE2 application targetting Mac OS and Windows. And I want to have integration into context menu. For windows this is simple task. But for Mac OS I dont know how to do this.
I've read Providing a Service documentation and tried similar code in Delphi but with no luck.
Look at simple code for Finder integration trials.
App.dpr
program App;
uses
SysUtils,
{$IFDEF MACOS}
AppKit, CocoaTypes, CoreFoundation,
CoreServices, Foundation, Mach, ObjCRuntime,
ObjectiveC, OCMarshal, OpenGL, QuartzCore, Security,
SystemConfiguration,
{$ENDIF}
MessageProvider;
{$IFDEF MACOS}
var
app: NSApplication;
provider: TMessageProvider;
{$ENDIF}
begin
Application.Initialize;
{$IFDEF MACOS}
provider := TMessageProvider.Create();
app := TNSApplication.Alloc();
app.setServicesProvider(provider);
{$ENDIF}
Application.CreateForm(TFormOSVersion, FormOSVersion);
Application.Run;
end.
MessageProvider.pas
unit MessageProvider;
interface
uses
FMX.Dialogs
{$IFDEF MACOS}
, AppKit, CocoaTypes, CoreFoundation,
CoreServices, Foundation, Mach, ObjCRuntime,
ObjectiveC, OCMarshal, OpenGL, QuartzCore, Security,
SystemConfiguration
{$ENDIF}
;
type
TMessageProvider = class
public
procedure simpleMessage(var userData: string; var error: string);
end;
implementation
procedure TMessageProvider.simpleMessage(var userData: string; var error: string);
begin
ShowMessage('Simple message from service.');
error := '';
end;
end.
Added configuration to info.plist
<key>NSServices</key>
<array>
<dict>
<key>NSKeyEquivalent</key>
<dict>
<key>default</key>
<string>e</string>
</dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>App/Message</string>
</dict>
<key>NSMessage</key>
<string>simpleMesage</string>
<key>NSPortName</key>
<string>App</string>
</dict>
</array>
When run this on Mac OS application hungs and sometimes crashes with 'Bus error' exception.
Can anybody help with this problem?
Or maybe Delphi XE2 doesnt support this kind of functionality?