title: Delphi Error: "Cannot focus a disabled or invisible window"
body: <p>I'm getting an error when running my compiled program. I've taken every precaution I can think of to prevent the error such as enabling forms before I hide or focus them. The application shows a <code>DimmerForm</code> (grey fade overlay) and then a <code>NewFileForm</code> on top of the overlay. The <code>NewFileForm</code> does its stuff and determines the file that is to be made and creates a new <code>tabsheet</code> in the page control on the <code>MainForm</code> and shows the newly created tab sheet. All this works so far (I can break before the <code>NewFileForm</code> closes and any error occurs and see that the tab sheet has been created and shown successfully). The <code>NewFileForm</code> then closes, which is again working fine.</p>
  
  <p>The error happens when anything then tries to set the focus back to the <code>MainForm</code>. Hiding the <code>DimmerForm</code>, or clicking on the <code>MainForm</code>, or setting focus to the <code>MainForm</code> through code all cause the error message to occur. Placing the code in a {<code>try</code>, <code>except</code>, <code>end</code>} doesn't prevent the error message either. I've searched every other method in the code that could possibly be triggered by the focusing of the <code>MainForm</code> and none are entered before the error occurs (so can't be causing it).</p>
  
  <p>I wrote pretty much the exact same code in a previous version of my application and then decided to restructure it all from the ground up. The previous version of the application worked without a hitch with the form focusing.</p>
  
  <p>Here is the code to open up the <code>NewFileForm</code>:</p>
  
  <pre><code>procedure TMainForm.NewFilesToolButtonClick(Sender: TObject);
  begin
  
    ShowDimmer;
    NewFileForm.ShowModal;
    HideDimmer;
  
  end;
  </code></pre>
  
  <p>Here is the code to show the dimmer form:</p>
  
  <pre><code>procedure ShowDimmer;
  begin
  
    // Enable to prevent errors
    DimmerForm.Enabled := true;
  
    // Hide dimmer form and show mainform
    DimmerForm.Show;
  
  end;
  </code></pre>
  
  <p>Here is the code to hide the dimmer form:</p>
  
  <pre><code>procedure HideDimmer;
  begin
  
    // Enable to prevent errors
    DimmerForm.Enabled := true;
    MainForm.Enabled := true;
  
    // Hide dimmer form and show mainform
    DimmerForm.Hide;
    MainForm.SetFocus;
  
  end;
  </code></pre>