ShowMessage() behavoir in FireMonkey on iOS


I have a simple FMX multi-device C++ app. The app has 1 Form and nothing else. In the Form’s OnShow event, I initiate a function I named StartupCode(). All of the code is shown below.

When I run the app on Windows, I get expected behavior – the 3 messages pop up in the correct order with the correct timing (e.g. each Sleep() only starts after the previous dialog box has been acknowledged by clicking OK).

When I run the app on iOS or Android, I get the last message popup first (“Slept 2 sec”) but only after the entire time has elapsed (12.25 seconds). Then immediately after acknowledging by clicking OK, I get the “Slept 10 sec” message, and likewise after that I get the “Slept quarter sec” message.

#include <System.SysUtils.hpp>

void StartupCode()
ShowMessage(“Slept quarter sec”);
ShowMessage(“Slept 10 sec”);
ShowMessage(“Slept 2 sec”);

void __fastcall TForm1::FormShow(TObject *Sender)
#if defined(_PLAT_IOS) || defined(_PLAT_ANDROID)
TThread::ForceQueue(nullptr, [this](){StartupCode();});

#if defined(_PLAT_MSWINDOWS)

I’m green and just trying to learn a bit. I was testing to see if a thread would get into trouble with Apple’s app start watchdog timers when I ran into this weird behavior.

Why does this behavior happen?

Comments are closed.