Author: Jonas Bilinkevicius
I'm trying to set up a "Please Wait" box. I want it to be modal in the sense that
my main form is deactivated while I have this box showing. But, in the function
that displays the "Please Wait" box, I want the code to continue rather than stall,
waiting for the box to close.
Answer:
1 { ... }2 WaitBox.Show; {shows your WaitBox}3 Enabled := false; {disables the whole main form (Self.Enabled)}4 Application.ProcessMessages; {let the two forms update themselves}5 try6 { ... Do next steps }7 finally8 Enabled := true;
9 WaitBox.Hide;
10 end;
Note that the WaitBox must be visible before you can disable the main form. You
needn't disable each single component. With this construction you can easily add a
Cancel-Button to your WaitBox. Set a public property (CancelPressed) to TRUE if the
Cancel Button is pressed and you can do something like this:
11 { ... }12 repeat13 { next steps }14 Application.ProcessMessages;
15 until16 WaitBox.CancelPressed
17 { ... }