title: How Can I Keep the FindDialog from Staying on Top (Delphi)?
body: <p>In Delphi 2009, I do a simple:</p>
  
  <pre><code>FindDialog.Execute;
  </code></pre>
  
  <p>The FindDialog window stays on top of my program's main window as it should.</p>
  
  <p>However, if I open another window from some other program over my own program's window, the FindDialog window remains on top of the other window.</p>
  
  <p>If I try this with a FindDialog from another program (e.g. Notepad), this does not happen. Opening another program's window over Notepad and its FindDialog will cover both the Notepad and FindDialog windows. This seems to be the correct and expected behavior.</p>
  
  <p>Is this something I'm doing wrong or is this a problem with the way Delphi has implemented the FindDialog?  Is there something I can do to make it work the Notepad way?</p>
  
  <hr>
  
  <p>Thank you all for the comments. The fact that you cannot reproduce my problem is already a clue that it is something else causing this. This will help me track it down. I'll research a little more and post additional info here when I find out something.</p>
  
  <hr>
  
  <p>Very interesting. My PrintDialog doesn't stay on top. Still don't know why my FindDialog does. Still researching...</p>
  
  <hr>
  
  <p>I changed the call to: FindDialog.Execute(Handle); Still on top.</p>
  
  <hr>
  
  <p>I added another FindDialog (this time FindDialog1) to my main form and I execute it at startup of my program. It has the same stay-on-top behavior. That at least indicates it wasn't anything to do with my FindDialog or customizations I made to do with it. So it must be a setting in my main form.</p>
  
  <hr>
  
  <p>It doesn't look like I'm the only one who's encountered this. See: <a href="http://www.restuner.com/news-history.htm" rel="nofollow">Resource Tuner: Version History</a> which appears to be a Delphi application, where under Version 1.99 it states: "Bugfix: The (search) dialog preview window stayed on top when switching to another application."  I might try contacting them and see if they might remember what their fix was.</p>
  
  <hr>
  
  <p>I add some new dialogs to my form and put these calls in one place:</p>
  
  <pre><code>FindDialog1.Execute();
  PrintDialog1.Execute();
  ReplaceDialog1.Execute();
  FontDialog1.Execute();
  </code></pre>
  
  <p>The FindDialog and ReplaceDialog stay on top in front of other windows.
  The PrintDialog and FontDialog do not stay on top and work as they should.</p>
  
  <p>So what is different between the two sets of dialogs that make the first two do it wrong?</p>
  
  <hr>
  
  <p><strike>Also, this problem happens in an old version of my program that was compiled with Delphi 4.</strike> Whoops. Now I see this problem did not happen in my old version that used Delphi 4. </p>
  
  <p>And it was a user who reported this problem. He uses Windows XP, and I'm developing on Vista, so it happens under different OS's.</p>
  
  <hr>
  
  <p>Confirmation: Yes, I create a new form and add a FindDialog on it. The FindDialog does NOT have the problem. This indicates something in my program is causing the FindDialog to stay on top. Now, I've just got to find out what that is. Any more ideas? If someone gives me an answer that even gives me a clue to help me solve this, then they'll get the accepted answer.</p>
  
  <hr>
  
  <p>Solution: Sertac's edit to his answer gave me the workaround:</p>
  
  <pre><code>  Application.NormalizeTopMosts;
    FindDialog.Execute();
    Application.RestoreTopMosts;
  </code></pre>
  
  <p>Doing this prevents the FindDialog from being TopMost when the Application is not TopMost.</p>
  
  <p>... But I still really don't understand this (the Delphi help on NormalizeTopMosts) is very confusing and doesn't indicate that it should do this.</p>
  
  <p>Hopefully this "fix" won't cause other problems.</p>