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

AndroidAppmethodCode SnippetDelphiFiremonkeyIOSOSXWindows

Write New Or Migrate Existing Code To Android And IOS Using Delphi XE6 Firemonkey

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

Delphi XE6 Firemonkey Migrate Code From Windows To Mobile | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSEmbarcadero has a resource up on their DocWiki where they cover how to move some code which is Windows based to mobile devices like Android and IOS. This information is for Delphi XE6 but most of it also applies to Delphi XE5. The topics that are covered are string types, zero based strings, new versions of Copy, Delete, Pos, and Trim, array types, catching hardware exceptions with try-except blocks, atomic intrinsics, and automatic reference counting.

The string types section is pretty complex and without going into much detail basically you need to be using these string types: System.String, System.Char,  System.Byte,  System.UInt8, System.SysUtils.TStringBuilder, System.String, System.MarshaledString.

The zero based vs. one based strings is also complex but basically in order to be cross platform compatible you need to not access characters in a string directly as if it was an array. Instead you need to use TStringHelper.Chars aka MyString.Chars[index].

Replacements for the Copy, Pos, Delete, and Trim functions which are cross platform are TStringHelper.IndexOf, TStringHelper.Remove, TStringHelper.Substring, and TStringHelper.Trim. So you would use MyString.IndexOf(‘123’) to do a Pos() on the contents of MyString for ‘123’.

The catching hardware exceptions by using a function within the try-except statement was something I didn’t even know before reading the article. Basically to catch hardware exceptions you have to use a function (that CAN NOT be inlined) inside of the try-except block instead of just having straight code.

The Object Pascal compilers don’t support built in assembly code on mobile but you can use atomic intrinsic functions which are System.AtomicExchange, System.AtomicIncrement, System.AtomicCmpExchange, and System.AtomicDecrement.

And lastly the mobile compiles support automatic reference counting. If you need to explicitly free an object you can use the DisposeOf function instead of the Free function. If you are running into Low Memory errors on IOS you might investigate how you can use DisposeOf on your objects instead of Free.

Head over and check out the full resource from Embarcadero about writing new code and migrating existing code to mobile devices.

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

Related posts
DelphiDemoFiremonkeyLinuxOSXShowcaseWindows

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

DelphiFiremonkeyShowcaseUtilityWindows

Unleashing Creativity With Song Writer AI: A Deep Dive

DelphiFiremonkeyShowcaseWindows

How To Build Stable Diffusion Text To Image Prompts

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

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