-1

What is the best way to update FMX control without using Apllication.Processmessages method, וn main form.

Apllication.Processmessages call can cause to unwanted asynchrony user events to come in before operation completed.

We have old delphi XE5 in ms windows 10, i tried repaint and invalidate but it not help.

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • 3
    It is a sound principle to avoid `Application.ProcessMessages`. Can you provide an example situation where you need to update an FMX control before the built in updating kicks in. Please provide a [mre] . – Tom Brunberg Jun 29 '22 at 06:56
  • 1
    Don't do time-consuming work in the GUI thread. Use background threads for such work, and only use the GUI thread for GUI interaction. Then all controls will repaint themselves without any delay. (And you can move and resize your forms all the time, etc.) – Andreas Rejbrand Jun 29 '22 at 09:13
  • For example , when user press button that process something that take a while, i want to disable the button (prevent another user click) and insert please wait message to the user. If i call Application.ProcessMessages During button process it is possible that the user press quick on other buttons that active. This can create unwanted asynchrony operation. – user19437371 Jun 29 '22 at 13:08
  • @user19437371 we understand what you want. You are like the bajillionst person to ask for this in Delphi's long history. What you have been told, by me and by Andreas, is the best way to handle this. – Remy Lebeau Jun 30 '22 at 04:19

1 Answers1

2

Have the OnClick handler disable the button, start a background thread/task to do the actual work, show the "please wait" message, and then exit the OnClick handler. Do not block the main thread at all. Let it run so it can process UI work normally as needed.

When your background work is finished, have the thread/task notify the main thread, which can then dismiss the "please wait" message and re-enable the button.

DO NOT do the actual work in the OnClick handler itself, and DO NOT call Application.ProcessMessages() at all.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thanks for your answer ,In my code i need to block any operations on my GUI until the button process will finish. The button operation is mandatory before the user can continue. – user19437371 Jun 30 '22 at 01:19
  • @user19437371 that doesn't change what I said. You can simply disable the Form as a whole until the background work is finished. Or, if the "please wait" message is a pop-up Form, you can display it modally until the work is finished. – Remy Lebeau Jun 30 '22 at 04:17