OnUpdateUI

 

OnUpdateUI is called when the command state is changed and it is time to update toolbar buttons, menus etc.
I always place the UI-updating stuff in  OnCommandStateChanged and have not been able to find situations where one could benefit from using OnUpdateUI instead. OnUpdateUI seems to be called more often then OnCommandStateChanged.

The following sample uses OnUpdateUI to make sure that menu-item 'Copy'  (CopyMenu) is enabled only when text has been selected.

 

function TForm1.EmbeddedWB1UpdateUI: HRESULT;
begin
CopyMenu.Enabled:=(Embeddedwb1.QueryStatusWB(OLECMDID_COPY)=OLECMDF_ENABLED or OLECMDF_SUPPORTED);
end;