title: Exception calling remote SOAP call from thread
body: <p>This is an extension / next step of <a href="https://stackoverflow.com/questions/2538655/should-i-free-a-delphi-object-auto-instantiated-from-a-web-services-call">this question</a> I asked a few minutes ago.  </p>
  
  <p>I've a Delphi application with a main form and a thread.  Every X seconds the thread makes a web services request for a remote object. It then posts back to the main form which handles updating the UI with the new information.</p>
  
  <p>I was previously using a TTimer object in my thread, and when the TTimer callback function ran, it ran in the context of the main thread (but the remote web services request did work).  This rather defeated the purpose of the separate thread, and so I now have a simple loop and sleep routine in my thread's Execute function.  The problem is, an exception is thrown when returning from GetIMySOAPService().</p>
  
  <pre><code>procedure TPollingThread.Execute;
  var
  SystemStatus : TCWRSystemStatus;
  begin
  while not Terminated  do
  begin
    sleep(5000);
    try
      SystemStatus := GetIMySOAPService().GetSystemStatus;
      PostMessage( ParentHandle, Integer(apiSystemStatus), Integer(SystemStatus), 0 );
      SystemStatus.DataContext := nil;
      LParam(SystemStatus) := 0;
    except
    end;
  end;
  end;
  </code></pre>
  
  <p>Can anyone advise as to why this exception is being thrown when calling this function from the thread? I'm sure I'm overlooking something fundamental and simple.</p>
  
  <p>Thanks, Duncan</p>