Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey, Delphi Android, Delphi IOS

Four Fundamental Ways To Interface With Objective-C In Delphi XE5 Firemonkey On OSX And IOS

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Delphi XE6 Firemonkey OSX APIs | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSJacob from TwoDesk Software Company has a blog post up about how to access Objective-C objects on OSX from Delphi XE5 & XE6 Firemonkey. It should also work in AppMethod and I believe these same methods that apply to OSX also apply to IOS. It covers how to access four different fundamental elements of Objective-C from Delphi. Those elements are static methods of an Objective-C class, an interface to a instance of an Objective-C class, an Objective-C object ID, and finally Delphi strings as NSStringObjects. The sample function that is demonstrated in the blog entry is a how to do a synchronous HTTP request using the native OSX TNSURLConnection object and return the results into a TMemo. The purpose being to use the native operating system object instead of using something like the TIdHTTP component which is the Indy HTTP request component. I think it does a really good job of explaining each type of object and how to access that object. Be sure to read the Recap section at the bottom of the post as it specifically tells you in a few lines exactly how to access the fundamental elements of the OSX API. Here is the final sample function for making an HTTP request:
procedure TForm1.Button1Click(Sender: TObject);
var
URL: NSURL;
URLRequest: NSURLRequest;
Data: NSData;
Response: Pointer;
begin
URL := TNSURL.Wrap(TNSURL.OCClass.URLWithString(
StrToNSStr('http://www.twodesk.com')));
URLRequest := TNSURLRequest.Wrap(TNSURLRequest.OCClass.requestWithURL(URL));
Data := TNSURLConnection.OCClass.sendSynchronousRequest(URLRequest, @Response,
nil);
Memo1.Lines.Text := PAnsiChar(Data.bytes);
end;

Head over and read the full blog post about accessing the OSX API with Object Pascal from Delphi Firemonkey.

Exit mobile version