RAD Studio VCL Reference
|
Occurs when the client event that is linked to it fires.
property OnExecute: TNotifyEvent;
__property TNotifyEvent OnExecute;
Write an OnExecute event handler when you want to respond when the user triggers the client object's default event (typically an OnClick event). For most target clients, OnExecute is triggered on a Click method, and is associated with the OnClick event.
OnExecute also occurs when the user types the shortcut (or one of the secondary shortcuts) associated with the action or its client.
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"); }
/* When a client component or control is clicked, the OnExecute event occurs for it’s 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 a TActionList (with one TAction) and a TToolBar on a form. Double click on the TActionList and create an 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 something that will make it obvious when it is visible. Also remember to uncheck Project|Options|Applications|Enable runtime 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"); else lbOther->Items->Add("Event Action1Execute: toolbar not visible"); }
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;
{ When a client component or control is clicked, the OnExecute event occurs for it’s 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 a TActionList (with one TAction) and a TToolBar on a form. Double click on the TActionList and create an 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. } type TMainForm = class(TForm) ActionList: TActionList; Action1: TAction; MainMenu: TMainMenu; MenuAction: TMenuItem; lbOther: TListBox; lblOther: TLabel; ToolBar1: TToolBar; procedure Action1Execute(Sender: TObject); private { Private declarations } public { Public declarations } end; var MainForm: TMainForm; implementation {$R *.dfm} procedure TMainForm.Action1Execute(Sender: TObject); begin { Toggle Toolbar1’s visibility } ToolBar1.Visible := not ToolBar1.Visible; if ToolBar1.Visible then lbOther.Items.Add('Event Action1Execute: toolbar visible') else lbOther.Items.Add('Event Action1Execute: toolbar not visible') end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|