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

AndroidAppmethodCode SnippetDelphiDemoFiremonkeyIOSOSXWindows

Easily Use Threads In Delphi XE5 Firemonkey On Android And IOS

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

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

There is a unit that comes with Delphi XE5 Firemonkey called AnonThread.pas which easily allows you to use threads in your Android and IOS applications. There is also a demo project that comes with XE5 Firemonkey in the Samples/Delphi/RTL/CrossPlatform Utils/AnonymousThread/ directory which shows you how to use them. David Clegg from Embarcadero has a blog post explaining the example and how to use the anonymous threads. One reason to use threads in your IOS application is apparently any synchronous network calls that you do need to be in a thread otherwise you run the risk of your app crashing. Lastly be sure to Synchronize() any graphical control updates. I am including an example procedure below:
procedure RunAnonymousThread;
var
FThread: TAnonymousThread<Boolean>;
begin
FThread := TAnonymousThread<Boolean>.Create(
function: Boolean
begin
// Runs in separate thread
// run your thread safe code
// example:
//RESTClient.Execute;
// remember in a thread any graphical changes have to be wrapped in Synchronize()
//Synchronize(
//procedure
// begin
//    Form1.Memo1.Lines.Add('Begin Execution');
//  end);
Result := True;
end,
procedure(AResult: Boolean)
begin
// Runs in main thread
// process the result from above
end,
procedure(AException: Exception)
begin
// Runs in main thread
// do something if there is an exception
end,
False);
end;

You can read the full blog post about anonymous threads here.

close

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

Related posts
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

DelphiIDEShowcaseWindows

Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores

DelphiFiremonkeyIDEIOSOSXWindows

DelphiCon 2020 FireMonkey Sessions Available Starting November 19

Sign up for our Newsletter and
stay informed

Leave a Reply to samsim Cancel reply