firemonkeyc++builderc++builder-10.2-tokyo

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?


Solution

  • 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; });
    }