title: Delphi Access to Thread Variables
body: <p>I have a thread that does a WMI query for me and I need to access some variables in the thread after it has executed the query. </p>
  
  <p>The thread is created as follows ...</p>
  
  <pre><code>procedure TFormMain.RunThread;
  var
    WMIQ: TThreadWmiQuery;
  begin
    WMIQ := TThreadWmiQuery.Create(True);
    ...
    WMIQ.OnTerminate := WMIQThreadOnTerminate;
    WMIQ.Resume;
  end;
  </code></pre>
  
  <p>and in the OnTerminate event I get the values I need like so ...</p>
  
  <pre><code>procedure TFormMain.WMIQThreadOnTerminate(Sender: TObject);
  begin
    Opcd := TThreadWmiQuery(Sender).P4COpcd;
    Role := TThreadWmiQuery(Sender).P4CRole;
    Usnm := TThreadWmiQuery(Sender).P4CUsnm;
  end;
  </code></pre>
  
  <p>I've been told that this may not the best way to access the thread variables. Is there any other, better, ways I can easily get data from my thread without too much complexity?</p>
  
  <p>Regards, Pieter</p>