TActionOnExecute (C++)

From RAD Studio Code Examples
Jump to: navigation, search


When a client component or control is clicked, the OnExecute event occurs for its associated action. For example, the following code illustrates the OnExecute event handler for an action that toggles the visibility of a toolbar when the action is executed. This example requires that a TActionList (with one TAction) and a TToolBar are on a form. Double-click the TActionList and create a TAction, named Action1. The TActionList must have no OnExecute event handler and the TAction has an OnExecute event handler, called Action1Execute. Then set an object's (such as a button or menu item) Action to Action1. Set the TToolbar color to one that will make it obvious when it is visible. Also, remember to uncheck Project > Options > Applications > Enable run-time themes.


void __fastcall TMainForm::Action1Execute(TObject *Sender)
  // Toggle Toolbar1's visibility
  ToolBar1->Visible = !ToolBar1->Visible;
  if (ToolBar1->Visible)
	lbOther->Items->Add("Event Action1Execute: toolbar visible");
	lbOther->Items->Add("Event Action1Execute: toolbar not visible");