Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement for deprecated Release function

As of C++Builder 10.2 Tokyo (and perhaps earlier), the FMX.Types.TFmxObject.Release() method is deprecated.

I use this method on some TForm objects for delayed destruction. All I can find (see these docs) is that (in C++) delete should be used instead, but I don't believe this marks a form for delayed destruction.

Is there a replacement for Release() that one ought to use in this case?

like image 704
Anthony Burg Avatar asked Jul 18 '26 12:07

Anthony Burg


1 Answers

I don't know why Embarcadero has deprecated Release() or what they intend it to be replaced with, but you could try using TThread::ForceQueue() to delete the TForm object, eg:

void __fastcall TMyForm::ReleaseMe()
{
    // Release()
    TThread::ForceQueue(NULL, &DeleteMe);
}

void __fastcall TMyForm::DeleteMe()
{
    delete this;
}

Or, if you are using a Clang-based compiler, you can use a C++11 lambda instead:

void __fastcall TMyForm::ReleaseMe()
{
    // Release()
    TThread::ForceQueue(nullptr, [this](){ delete this; });
}
like image 90
Remy Lebeau Avatar answered Jul 21 '26 13:07

Remy Lebeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!