I have an app using Rad Studio c++ 10.2.
My problem is to have a sequence of :SetupDelay ->ExerciseDelay->Rest Delay
before moving to the next exercise.
The UI presents the current exercise attributes and Must wait for each of these delays sequentially before continuing to the next.
I have the following code using a TTimer which works on Windows, but when I compile for Android it causes the UI to crash.
I am looking for a portable method which supports all platforms (Win,OSX,IOS,Android) supported by Rad Studio. Below is the code that I first used for windows:
While the delay is happening there are several buttons that need to be serviced in case of Skip,Pause,Cancel so that the user is not locked in during the delay phase.
My process is: (Sequential process in UI)
1: Display current exercise attributes
2: Delay for Setup - Countdown timer updates label each second
3: Delay for Exercise Time - Countdown timer updates label each second
4: Delay for Rest time - Countdown timer updates label each second
5; Update set counter and loop (3-4) until all sets for current exercise are completed
While inside the delay the UI must be active so that all the buttons (Next,Pause,Cancel) respond quickly.
To clarify: The code written for Rad Studio is multi-device so the same code compiled/run for Windows fails on Android. The failure on Android is as follows:
When the timer first runs the Android app freezes and none of the timers run. If I click any of the buttons, the app crashes. If I do nothing the app just sits there and does nothing.
What I wanted to do is run the delay within a thread but there is no way I can see to wait for that thread to finish from the main UI thread without blocking, which is basically the same problem I have without the threaded approach.
Any help or idea would be appreciated.
What I have tried:
Below is my existing code working for Windows.
I tried using a separate thread for the delay, but the issue is still the UI waiting for the delay to finish involves constantly checking the delay status which effectively halts the UI. As far as I can determine Android does not support ProcessMessages so any solution should not use this method.
void __fastcall TTabbedwithNavigationForm::DoDelay( int delay )
{
int pdl;
char buf[ 256 ];
NEXT = false;
CANCEL = false;
DelayCounter = delay;
Timer1 ->Enabled = true;
pdl = 5000;
while ( DelayCounter > 0 )
{
if ( --pdl == 0 )
{
sprintf( buf, "%3d", DelayCounter );
LBL_RestExerciseTime ->Text = buf;
Application ->ProcessMessages();
pdl = 5000;
}
else
{
}
if ( CANCEL == true )
break;
if ( NEXT == true )
break;
}
Timer1 ->Enabled = false;
}
void __fastcall TTabbedwithNavigationForm::Timer1Timer(TObject *Sender)
{
if ( DelayCounter > 0 )
{
--DelayCounter;
if ( STOP == true || CANCEL == true )
{
Timer1 ->Enabled = false;
DelayCounter = 0;
}
if ( DelayCounter == 0 )
{
Timer1 ->Enabled = false;
}
}
}