Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Rather than creating a loop that occasionally calls <code>Application.ProcessMessages</code> you can create a descendant of <code>TThread</code> and move the socket request to the <code>TThread.Execute</code> method. Use TThread.OnTerminate to notify your form(or any other class) when the thread has completed its work.</p> <p>There is <a href="http://radstudiodemos.svn.sourceforge.net/viewvc/radstudiodemos/branches/RadStudio_XE/Delphi/RTL/Threads/" rel="nofollow noreferrer">sample code</a> which gives more details about how to use <code>TThread</code>.</p> <p>There are several other <a href="https://stackoverflow.com/q/3419945/71200">3rd party</a> threading libraries that either provide more flexibility or are easier to use than <code>TThread</code> and I would highly recommend any of them over <code>TThread</code> if you are new to multi-threading.</p> <p>Note: There are some serious <a href="http://delphi.about.com/od/objectpascalide/a/delphi-processmessages-dark-side.htm" rel="nofollow noreferrer">side-effects</a> to using <code>Application.ProcessMessages</code>. You are seeing one of them in your code with the dll unlocking the application's mainform. It breaks the single-threaded UI model the VCL is build upon. <code>ProcessMessages</code> has its place but using threads is more appropriate for the situation you're describing.</p> <pre><code>var Slowpoke: TMyLongRunningProcessThread; procedure MyWaitProc(Completed:TNotifyEvent) begin Slowpoke := TMyLongRunningProcessThread.Create(True); Slowpoke.FreeOnTerminate := True; Slowpoke.OnTerminate := Completed; Slowpoke.Resume; end; </code></pre> <p><code>MyWaitProc</code> returns immediately after starting the thread so the GUI is free to respond to user actions. When the thread terminates it calls the event handler pointed to by <code>Completed</code>.</p> <p>Obviously if you need to retrieve data from the thread you'll want to either have the thread write to an accessible memory location before it Frees itself or remove the <code>FreeOnTerminate</code> so the data can be retreived from the thread through a property.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload