Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7702579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:15:32+00:00 2026-05-31T23:15:32+00:00

I have a Delphi 2006 app which can pop up a modal dialog in

  • 0

I have a Delphi 2006 app which can pop up a modal dialog in response to an error condition. It seems to get itself into a state where one of these modal dialogs is open, positioned in front of the main form, but neither form is responding to messages. Clicking on either gives a “bonk”. The app is running fine, the UI is updating the main form, but you can’t do anything. I guess there is most likely another modal dialog under the main form. Whether it is one of mine or one from Windows I have no idea.

Other points:

  • the app responds to keyboard shortcuts OK. One of these shortuts shuts down the app gracefully and this worked. I have been unable to reproduce the situation since.
  • the app has a tray icon. This responds to right mouse clicks. If I minimize the app from here the main form minimizes and leaves the modal dialog displayed, still without focus. If I restore the main form, things are as they were, with neither window having focus. Alt-tab has similar results.
  • platform is Windows 7
  • I call DisableProcessWindowsGhosting before any forms are created
  • I open the modal dialogs with

    ModalDialog.PopupParent := MainForm ;
    ModalDialog.ShowModal ;
    
  • I postpone these error dialogs if other modal dialogs are open:

    if (Application.ModalLevel = 0) then
        {open modal dialog}
    

My question has two parts:

Is there a way of programmatically finding out what window has focus? I could then take some action for this scenario or a last resort I could them provide a shortcut key to bring it to the front or take some evasive action (depending on the dialog) like set the ModalResult to mrCancel.

How can this situation arise? Normally when I get a modal dialog behind the main form (I can do that by getting the modal dialog to open, minimizing the app from the tray icon, then restoring the app again – the app main form restores in front of the dialog, with the dialog still retaining focus), I can bring it to the front again by clicking on the tray icon, or close it with the Esc key but it didn’t work in this case.

**UPDATE**

Misha’s fix worked apart from non-delphi dialogs like TSaveDialog. I was able to get them to work as well by adding Application.ModalPopupMode := pmAuto ; just before the call to Execute.

By “got it to work” I mean that the save dialog was in front after the following sequence:

  • open save dialog
  • minimize app from tray icon
  • restore app from tray icon

whereas it was behind the main form without the ModalPopupMode := pmAuto.

So I’m hoping these changes will help the (as yet unreproduced) problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:15:34+00:00Added an answer on May 31, 2026 at 11:15 pm

    The last active popup window (VCL or not) can be queried with GetLastActivePopup:

    function GetTopWindow: HWND;
    begin
      Result := GetLastActivePopup(Application.Handle);
      if (Result = 0) or (Result = Application.Handle) or
          not IsWindowVisible(Result) then
        Result := Screen.ActiveCustomForm.Handle;
    end;
    

    This is somewhat copied from TApplication.BringToFront.

    Bringing this window to the front can be done by SetForegroundWindow:

    SetForegroundWindow(GetTopWindow);
    

    Note that Application.BringToFront might do the trick altogether, but I once experienced it did not function properly, a situation I have not been able to reproduce since though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Delphi 2006 app that pops up a modal alert dialog when
We have a large (about 580,000 loc) application which in Delphi 2006 builds (on
I have a Delphi 2006 app that I am adding code to process some
I have an Oracle 9 database from which my Delphi 2006 application reads data
I have a problem migrating from Delphi 2006 to Delphi 2009. A Project which
I have a Delphi 2006 app that writes to a file and then regularly
I have a Delphi 2006 app with a CHM help file. It all works
I have a very strange problem with the Delphi 2006 IDE. If the IDE
I have a classic client/server (fat client and database) program written in Delphi 2006.
I have a delphi (Win32) web application that can run either as a CGI

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.