TActionOnUpdate (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

When the application is idle, the OnUpdate event occurs for every action that is linked to a visible control or menu item that is showing. This provides an opportunity for applications to execute centralized code for enabling and disabling, checking and unchecking, and so on. For example, the following code illustrates the OnUpdate event handler for an action that is "checked" when the toolbar is visible. This example requires a TActionList (with one TAction) and a TToolBar on a form. Double-click the TActionList and create an TAction named Action1. The TAction has an OnUpdate event handler called Action1Update. Then set an object's (such as a button or menu item) Action to Action1.

Code

procedure TMainForm.Action1Update(Sender: TObject);
begin
  if ((Sender as TAction).Checked <> ToolBar1.Visible) then
    lbOther.Items.Add('Event Action1Update: toolbar visibility changed');
	{ Indicate whether ToolBar1 is currently visible. }
	(Sender as TAction).Checked := ToolBar1.Visible;
end;

Uses