title: Order of TForm creation and destruction and threads
body: <p>I have a thread which calls functions of certain form to update this form. When task is done, thread updates form with results, using <code>Synchronize</code> and it all works fine while the program is running.</p>
  
  <p>The problem happens when the thread is running and I close the program I got access violation. It was caused by thread updating form which was already released. After rearranging order of form creation (calls to <code>Application-&gt;CreateForm</code>) it worked fine because now the form that holds thread code is created before form that is updated. It seems that order of destruction is reverse to creation order.</p>
  
  <p>I also added some code in form destructor to make sure thread is terminated if form is destroyed before form with the thread code. So rearranging form creation order and/or code in form destructor solves the problem.</p>
  
  <p>But I have 3 questions:</p>
  
  <ol>
  <li><p>What is the order in which created forms are destroyed? Is it reverse of the creation order as I assume now?</p></li>
  <li><p>Is there a better way to do the above task - update form GUI items after thread is done processing data. Right now I do it from thread itself using <code>Synchronize</code> but someone experienced with threads may have better idea. One other idea I had was to even remove a bunch of <code>CreateForm</code> generated by compiler and create them manually, only create main form using <code>CreateForm</code> to better control order of destruction (as suggested by Rob Kennedy - <a href="http://pages.cs.wisc.edu/~rkennedy/createform" rel="nofollow">http://pages.cs.wisc.edu/~rkennedy/createform</a>).</p></li>
  <li><p>How expensive is dynamic form creation/destruction in typical application? Is it better to use form Hide and keep in memory or destroy it on close?</p></li>
  </ol>