0

I use the dialog to confirm user actions:

TDialogService.MessageDialog('Question?', System.UITypes.TMsgDlgType.mtInformation,
[System.UITypes.TMsgDlgBtn.mbYes, System.UITypes.TMsgDlgBtn.mbNo],
System.UITypes.TMsgDlgBtn.mbNo, 0,

// Use an anonymous method to make sure the acknowledgment appears as expected.
procedure(const AResult: TModalResult)
begin
if Result = mrNo then
Exit
else begin
...
ProgressBar1.Visible := True;
ProgressBar1.Value := i;
Application.ProcessMessages;
...

But since MessageDialog is executed in a separate thread, nothing happens on the screen. How do I make the ProgressBar display and change its values?

I tried to turn on the timer before calling the dialog, changed the value of an external variable inside the dialog, and processed this value in the timer, but nothing happened

3
  • 2
    "MessageDialog is executed in a separate thread" - that is not true. It simply runs asynchronously instead. There is a difference. It still runs in the UI thread, it just doesnt block the caller. So you have to make sure that after MessageDialog returns to your code that you don't subsequently block the UI thread message loop so it can process the dialog and call your anonymous procedure when the dialog is closed. Commented Sep 1, 2023 at 14:03
  • Okay, I got that. How then, in principle, to organize the rendering of the progress of long-term processes? Commented Sep 5, 2023 at 5:46
  • preferrably by doing the long processes in a separate thread, not in the UI thread. Send notifications to the UI thread when you need to access UI resources for reporting status, asking for input, etc. Rule of thumb - never block a UI thread. Commented Sep 5, 2023 at 7:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.