Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement x:y named delegate methods?

I'd like to create a WebView's WebFrameLoadDelegate's method in Delphi for this obj-c method:

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame

How should this method be declared in delphi?

These don't work:

public
    procedure didFinishLoadForm( webView:WebView; Sender:WebFrame ); cdecl;
    procedure webViewdidFinishLoadForm( webView:WebView; Sender:WebFrame ); cdecl;

Setting the delegate class seems to be OK using webview.setFrameLoadDelegate( d.GetObjectID );

Where d is TMyWebViewDelegate( TOCObject ) class, with GetObjectiveClass overridden, returning an interface(NSObject), like for the toolbar delegate here http://delphihaven.wordpress.com/2012/07/15/using-the-cocoa-toolbar-nstoolbar-in-xe2/

But my method is not called. What's the pattern for declaring such obj-c methods?

like image 779
kgz Avatar asked Oct 17 '14 15:10

kgz


2 Answers

Usually it is best to use the exact names of the methods and parameters (as answered by Rudy). But sometimes this is not possible. Two functions might need to have the same name, but have identical parameter types so that overload cannot be used. In that case you can use the MethodName attribute. So here's another valid solution:

[MethodName('webView:didFinishLoadForFrame:')]
procedure webViewdidFinishLoadForm( Sender:WebView; Frame:WebFrame ); cdecl;
like image 153
Sebastian Z Avatar answered Sep 24 '22 05:09

Sebastian Z


The correct syntax to implement the routine would be:

procedure webView(sender: WebView; didFinishLoadForFrame: WebFrame);

The name of the Objective-C selector is webView:didFinishLoadForFrame:. The first part must become the exact name of the method, the following parts must become the exact names of the parameters (case sensitive, because Objective-C is case sensitive). That is how Delphi maps method names to selectors.

like image 36
Rudy Velthuis Avatar answered Sep 24 '22 05:09

Rudy Velthuis