Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suspect that the question boils down to what you mean when you say:</p> <blockquote> <p>A message box does not block the main application.</p> </blockquote> <p>What I take this to mean is that when you show the message box, your VCL form can still be interacted with. The issue here is unrelated to threads and I suggest we remove them from the equation. Your understanding of what <code>Synchronize</code> does is sound.</p> <p>The issue is entirely related to the concept of a <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632599.aspx#owned_windows">window's owner</a>, and how modal dialog windows behave with respect to their owners. Note that by owner, I don't mean the Delphi property <code>TComponent.Owner</code>, but I mean the Windows API meaning of <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632599.aspx#owned_windows">owner</a>.</p> <p>Create a VCL app and drop two buttons on the form. Add the following <code>OnClick</code> handlers.</p> <pre><code>procedure TForm1.Button1Click(Sender: TObject); begin MessageBox(0, 'Not owned', nil, MB_OK); end; procedure TForm1.Button2Click(Sender: TObject); begin MessageBox(Handle, 'Owned by the VCL form', nil, MB_OK); end; </code></pre> <p>Now observe what happens when you click on <code>Button1</code>. The message box shows, but you can still click on the VCL form. And compare with <code>Button2</code>. When it shows the message box, the VCL form cannot be interacted with.</p> <p>When a modal dialog window is shown, the dialog window disables its owner. In the case of <code>Button2</code>, the owner is the VCL form. And once the form is disabled, you cannot interact with it. In the case of <code>Button1</code>, there is no owner and so the modal dialog window does not disable any other window. That's why the VCL form can be interacted with.</p> <p>Raymond Chen has a long series on modality at his Old New Thing blog:</p> <ul> <li><a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/02/18/376080.aspx">Modality, part 1: UI-modality vs code-modality</a></li> <li><a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/02/21/377337.aspx">Modality, part 2: Code-modality vs UI-modality</a></li> <li><a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/02/22/378018.aspx">Modality, part 3: The WM_QUIT message</a></li> <li><a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/02/23/378866.aspx">Modality, part 4: The importance of setting the correct owner for modal UI</a></li> <li><a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/02/24/379635.aspx">Modality, part 5: Setting the correct owner for modal UI</a></li> <li><a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/02/28/381591.aspx">Modality, part 6: Interacting with a program that has gone modal</a></li> <li><a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/03/01/382380.aspx">Modality, part 7: A timed MessageBox, the cheap version</a></li> <li><a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/03/04/385100.aspx">Modality, part 8: A timed MessageBox, the better version</a></li> <li><a href="http://blogs.msdn.com/b/oldnewthing/archive/2011/01/21/10118482.aspx">Modality, part 9: Setting the correct owner for modal UI, practical exam</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload