The forum is in read only mode.

  • Page:
  • 1

TOPIC: How to 'DESTROY' a TCppTask?

How to 'DESTROY' a TCppTask? 7 years 11 months ago #2399

I'm trying to write a simple TTask method that creates a TPopup containing a TAniIndicator - so I can show a wait cursor on Android and iOS while background tasks are processing (if someone already has solved this - I'd really like to see the code).

For the Invoke(), I have the following:

void __fastcall Invoke()
popup = new TPopup(NULL);
popup->Parent = db->mainForm;
TAniIndicator *ani = new TAniIndicator(popup);

This all works as expected when invoked via

cursorTask[0] = TTask::Run(_di_TProc(new TCppCursorTask()));

The problem is, when I cancel the task via


The popup is still visible - because it hasn't been destroyed. I've tried adding a ~TCppCursorTask method as well as a Destroy() method, but they don't get invoked when Cancel is called.

How to 'DESTROY' a TCppTask? 7 years 11 months ago #2402

TTask will create a thread to run that code. GUI Code is not thread safe, it's not wise to do that as you may get unexplained errors. GUI code should always be run in the main thread.

That said your error is easily explained, the TTask you create knows nothing about the visual controls you have created so calling Cancel will do nothing.

According to the documentation TPopup was designed to be shown and closed using:

popup->IsOpen = true;
popup->IsOpen = false;
  • Page:
  • 1
Moderators: April Anne