RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TApplicationEvents.OnActionExecute Event

Occurs when an action's Execute method is called and its action list has not already handled it.

Pascal
property OnActionExecute: TActionEvent;
C++
__property TActionEvent OnActionExecute;

Use the OnExecute event handler to respond when a user invokes actions whose action lists do not have OnExecute event handlers. 

If the action list that contains the action does not handle it in an OnExecute event handler, then the action is routed to the Application object's OnActionExecute event. The application events object hooks this event and responds with its own OnActionExecute event handler. 

The Handled parameter of the event handler returns false by default. If the handler handles the event, it should change Handled to true, thereby preventing further attempts to handle the action. When the event handler exits with Handled set to false, the event first goes to any other application events objects, and then the action's OnExecute event occurs. If the action remains unhandled after that, the active control's ExecuteAction method is called to allow the action to execute with an identified target. Finally, the active form's ExecuteAction method is called if all other handlers do not handle the action.

Note: Call the CancelDispatch method from an OnActionExecute event handler to prevent the application from forwarding the event to any other application events objects.
 

C++ Examples: 

 

/*
This example requires a TApplicationEvents, a TActionList
and a TListBox in the form.  Select the TApplicationEvents,
double click on the OnActionExecute event and add the
following code to the handler.  Create an TAction named
MyAction in a TActionList.  The TActionList must have no
OnExecute event handler, and the TAction has an OnExecute
event handler called MyActionExecute.  Then set an object's
(such as a button) Action to MyAction.  The Handled
parameter of the event handler returns false by default. If
the handler handles the event, it should change Handled to
true, thereby preventing further attempts to handle the
action.
*/
void __fastcall TAppEventForm::ApplicationEventsActionExecute(
      TBasicAction *Action, bool &Handled)
{
    lbOther->Items->Add("Event OnActionExecute");
}

void __fastcall TAppEventForm::ActionExecute(TObject *Sender)
{
    ShowMessage("Action executed");
}

 

Delphi Examples: 

{
This example requires a TApplicationEvents, a TActionList
and a TListBox in the form.  Select the TApplicationEvents,
double click on the OnActionExecute event and add the
following code to the handler.  Create an TAction named
MyAction in a TActionList.  The TActionList must have no
OnExecute event handler, and the TAction has an OnExecute
event handler called MyActionExecute.  Then set an object's
(such as a button) Action to MyAction.  The Handled
parameter of the event handler returns false by default. If
the handler handles the event, it should change Handled to
true, thereby preventing further attempts to handle the
action.
}
procedure TMainForm.ApplicationEventsActionExecute(Action: TBasicAction;
  var Handled: Boolean);
begin
  lbOther.Items.Add('Event OnActionExecute');
end;

procedure TMainForm.MyActionExecute(Sender: TObject);
begin
  ShowMessage('Action executed');
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!