delphivcltbutton

What exactly does Button.Update do in Delphi?


I noticed that within Delphi you can call the Update procedure on a TButton component by saying Button.Update().

The Update procedure is also available on some other components.

What exactly does this Update procedure do and when would you use it?


Solution

  • The Update procedure is inherited from the TWinControl class which, in turn, inherits from the TControl class.

    enter image description here

    Check the documentation:

    Vcl.Controls.TControl.Update

    Processes any pending paint messages immediately.

    Call Update to force the control to be repainted before any more, possibly time-consuming, processing takes place. Use Update to provide immediate feedback to the user that cannot wait for the Windows paint message to arrive.

    Update does not invalidate the control, but simply forces a repaint of any regions that have already been invalidated. Call Repaint instead to invalidate the control as well.

    Vcl.Controls.TWinControl.Update

    Forces the control to update.

    Update repaints any part of the control surface that is out of date. Normally, updates occur automatically, but an Update call may be necessary before lengthy processing that might interfere with automatic updates. Calling Update unnecessarily can increase overhead and cause screen flicker.

    Update only repaints areas of the control the have been determined to be out of date. To force immediate repainting of the entire control, call the Repaint method. To notify a control that it is out of date (without forcing an immediate repaint), call the Invalidate method.