Embarcadero 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.
Write New Or Migrate Existing Code To Android And IOS Using Delphi XE6 Firemonkey by Delphi XE5 XE6 XE7 XE8 10 Seattle Berlin Firemonkey, Delphi Android, Delphi IOS is licensed under a Creative Commons Attribution 4.0 International License.