TActionOnUpdate (C++)

From RAD Studio Code Examples
Jump to: navigation, search


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 a 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.


Boolean checked;

void __fastcall TForm1::Action1Update(TObject *Sender)
   // Indicate whether ToolBar1 is currently visible.
   TAction* pa = dynamic_cast<TAction*>(Sender);
   if (pa)
	 if (checked != ToolBar1->Visible)
	     lbOther->Items->Add("Event Action1Update: toolbar visibility changed");
	 checked = ToolBar1->Visible;
   // pa->Checked = True;  // Set this statically and do not change it.


Personal tools