Search code examples
c++indy10

TIdAntiFreeze Implementation


Under Delphi XE8's FormCreate, i am using the following syntax to apply the AntiFreeze function:

if Assigned(AntiFreeze) then FreeAndNil(AntiFreeze);

// or sometimes: AntiFreeze := TIdAntiFreeze.Create(NIL);

I trying to implement it in C ++ Builder XE8, like this:

   if (AntiFreeze->Assign()) {
     AntiFreeze->Active;
     AntiFreeze->Free();
   } 

But it does not work. I need help you to tell me the correct way.

Thank you so much..


Solution

  • The Delphi code is freeing a TIdAntiFreeze component that has been placed on the Form at design-time. If you don't want the component, don't put it on the Form in the first place.

    That being said, the C++ equivalent of the Delphi code would be:

    if (AntiFreeze) FreeAndNil(AntiFreeze);
    
    // or sometimes: AntiFreeze = new TIdAntiFreeze(NULL);
    

    That being said, you really should strive to not use TIdAntiFreeze at all. You should not be doing anything in the context of the main UI thread that blocks the main message loop for more than a few seconds at most. Most Indy operations are better suited for use in worker threads instead of the main UI thread. TIdAntiFreeze only works in the main UI thread, by pumping the main message loop while Indy operations are blocking the main thread.