Web Browsing Not Displaying on MacOS Using Delphi XE2

I started converting Webview interfaces that will be used in Delphi. I managed to load the webkit library, and the interface methods that are called work correctly, however I cannot show Webview in the main form.

Below are my interfaces declared

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; 

And here is the code for building 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; 

The code is executed without any exceptions, but just does not want to appear. What needs to be done differently in Delphi? The examples I found for the C lens look pretty simple:

Some objective C examples I have seen mark IBOutlets. This does not seem to apply to Delphi.

How do I get a WebView OSX Xcode project to load a URL at startup?

Thank.

+73
delphi freepascal webkit delphi-xe2 macos
Mar 16 '12 at 4:16
source share
2 answers

Getting the NSWindow of a FMX form
convert TForm link to NSWindow
install 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; 
+7
Apr 03 '13 at 19:43
source share

Have you considered the Chromium Embedded port for Delphi ?

+2
Apr 04 '13 at 5:18
source share



All Articles