使用Delphi XE2在MacOS中不显示Webview [英] Webview not displaying in MacOS using Delphi XE2

查看:98
本文介绍了使用Delphi XE2在MacOS中不显示Webview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始转换Webview接口以在Delphi中使用.我已经设法加载了Webkit库,并且调用的接口方法似乎可以正常工作,但是,我似乎无法在主窗体上显示Webview.

I have started to convert the Webview interfaces to be consumed in Delphi. I have managed to get the webkit library to load, and the interface methods that is called appears to work correctly, however, I cannot seem to display the Webview on the main form.

下面是我声明的接口

  WebFrameClass = interface(NSObjectClass)
  ['{7BE750C8-DFEC-4870-851A-12DBCB0B78F6}']
  end;

  WebFrame = interface(NSObject)
  ['{BCFA04BE-41AB-4B78-89C0-3330F12C7695}']
    procedure loadRequest(request: NSURLRequest); cdecl;
  end;
  TWebFrame = class(TOCGenericImport<WebFrameClass, WebFrame>)  end;

  WebViewClass = interface(NSViewClass)
  ['{0D9F44B7-09FD-4E35-B96E-8DB71B9A2537}']
    {class} function canShowMIMEType(MIMEType: NSString): Boolean; cdecl;
  end;

  WebView = interface(NSView)
  ['{C36D8016-2FCB-49F0-BA1C-C9913A37F9AC}']
    procedure clos; cdecl;
    procedure setHostWindow(hostWindow: NSWindow); cdecl;
    function initWithFrame(frame: NSRect; frameName: NSString; groupName: NSString): Pointer; cdecl;
    function mainFrame: WebFrame; cdecl;
  end;
  TWebView = class(TOCGenericImport<WebViewClass, WebView>)  end;

下面是构建WebView的代码:

And here follows to code to construct a WebView:

procedure TForm2.Button1Click(Sender: TObject);
var
  PWebView: Pointer;
  FwkMod: HMODULE;
  MyWebView: WebView;
  urlStr: NSURL;
  urlreq: NSURLRequest;
const
  WebKitFWK: string = '/System/Library/Frameworks/WebKit.framework/WebKit';
begin
  FwkMod := System.SysUtils.LoadLibrary(PWideChar(WebKitFWK));
  PWebView := TWebView.Alloc.initWithFrame(MakeNSRect(10, 10, 300, 300), nil, nil);
  MyWebView := TWebView.Wrap(PWebView);

  urlStr := TNSURL.Create;
  urlstr.initWithString(NSSTR('http://google.com.au/'));
  urlreq := TNSURLRequest.Create;
  urlreq.initWithURL(urlstr);
  MyWebView.mainFrame.loadRequest(urlreq);
end;

执行代码时不会引发任何异常,但只是不想出现.在Delphi中需要做些什么不同的事情?我为目标C找到的示例似乎很简单:

The code executes without raising any exceptions, but just does not want to appear. What needs to be done differently in Delphi? The examples I found for objective C appears to be quite simple:

我见过一些客观的C例子提到了IBOutlets.看起来这与Delphi无关.

Some objective C examples I have seen mention IBOutlets. It does not look like this is relevant for Delphi.

如何制作WebView OSX Xcode项目是否在启动时加载URL?

谢谢.

推荐答案

Getting the NSWindow of a FMX form
将TForm引用转换为NSWindow
设置主机窗口.
MyWebView.setHostWindow(MyNSWindow)

Getting the NSWindow of a FMX form
convert a TForm reference to a NSWindow
set Host Window.
MyWebView.setHostWindow(MyNSWindow)

procedure TForm2.Button1Click(Sender: TObject);
var
[...]
 ObjTOC: TOCLocal;
 MyNSWindow : NSWindow;
[...]  
 ObjTOC := (FmxHandleToObjC(Form2.Handle) as TOCLocal);
 MyNSWindow := NSWindow(TOCLocalAccess(ObjTOC).Super);

PWebView := TWebView.Alloc.initWithFrame(MakeNSRect(10, 10, 300, 300), nil, nil);
 MyWebView := TWebView.Wrap(PWebView);
 MyWebView.setHostWindow(MyNSWindow);

[...]
 MyWebView.mainFrame.loadRequest(urlreq);
end;

这篇关于使用Delphi XE2在MacOS中不显示Webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆