Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AppmethodCode SnippetDelphiFiremonkeyIOSOSX

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);
URLRequest: NSURLRequest;
Data: NSData;
Response: Pointer;
URL := TNSURL.Wrap(TNSURL.OCClass.URLWithString(
URLRequest := TNSURLRequest.Wrap(TNSURLRequest.OCClass.requestWithURL(URL));
Data := TNSURLConnection.OCClass.sendSynchronousRequest(URLRequest, @Response,
Memo1.Lines.Text := PAnsiChar(Data.bytes);

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

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts

AutoBlogAI: FireMonkey Client To Leverage LLMs And Generative AI For Blogging


Unleashing Creativity With Song Writer AI: A Deep Dive


How To Build Stable Diffusion Text To Image Prompts


FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

Sign up for our Newsletter and
stay informed

Leave a Reply