Difference between revisions of "TAction"
m (Fixed syntax highlighting) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{TAction}} | ||
+ | |||
A '''TAction''' object is a container for specific action-related topics like events, description, help-topic, icon, shortcut(s). When using TActions in the Action-property of buttons, menus, dialogs, controls it is possible to centralize the effects of mouse-clicks, menu-choices, dialog-selections, shortcuts etc. in a single event handler. | A '''TAction''' object is a container for specific action-related topics like events, description, help-topic, icon, shortcut(s). When using TActions in the Action-property of buttons, menus, dialogs, controls it is possible to centralize the effects of mouse-clicks, menu-choices, dialog-selections, shortcuts etc. in a single event handler. | ||
==Example== | ==Example== | ||
+ | |||
We want to have a TAction that handles opening of some other form. Make sure to have a [[TActionList]] on the main form. | We want to have a TAction that handles opening of some other form. Make sure to have a [[TActionList]] on the main form. | ||
− | Doubleclick the TActionList to get the [[ActionList Editor]]. Create a new action by hitting the plus-sign. In the [[Object Inspector]], set the name to actSomeAction, set a desired shortcut, a caption to be uses in menu's, an imageindex if a [[TImageList]] is connected to the parent ActionList, Hint is hints are to be displayed, helpkeyword and other properties where relevant. | + | Doubleclick the TActionList to get the [[ActionList Editor]]. Create a new action by hitting the plus-sign. In the [[IDE Window: Object Inspector|Object Inspector]], set the name to actSomeAction, set a desired shortcut, a caption to be uses in menu's, an imageindex if a [[TImageList]] is connected to the parent ActionList, Hint is hints are to be displayed, helpkeyword and other properties where relevant. |
The most important is the OnExecute-event that will be executed if the action is triggered somehow (menu, shortcut, button). | The most important is the OnExecute-event that will be executed if the action is triggered somehow (menu, shortcut, button). | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
procedure TMyForm.actSomeActionExecute(Sender: TObject); | procedure TMyForm.actSomeActionExecute(Sender: TObject); | ||
var | var | ||
Line 22: | Line 25: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | If you use the newly created action in a TMainMenu or TPopupMenu you are ready to go. | + | If you use the newly created action in a [[TMenuItem]] of a [[TMainMenu]] or [[TPopupMenu]] you are ready to go. |
== See also == | == See also == | ||
+ | |||
* [[doc:lcl/actnlist/taction.html|TAction documentation]] | * [[doc:lcl/actnlist/taction.html|TAction documentation]] | ||
− | * [[TActionList]] | + | * [[TActionList]] |
− | + | * [[TActionLink]] | |
− | + | * [[TActionListEnumerator]] | |
+ | * [[TContainedAction]] | ||
+ | * [[TCustomAction]] | ||
+ | * [[TCustomActionList]] | ||
+ | * [[TShortCutList]] |
Latest revision as of 05:28, 29 February 2020
│
English (en) │
español (es) │
A TAction object is a container for specific action-related topics like events, description, help-topic, icon, shortcut(s). When using TActions in the Action-property of buttons, menus, dialogs, controls it is possible to centralize the effects of mouse-clicks, menu-choices, dialog-selections, shortcuts etc. in a single event handler.
Example
We want to have a TAction that handles opening of some other form. Make sure to have a TActionList on the main form. Doubleclick the TActionList to get the ActionList Editor. Create a new action by hitting the plus-sign. In the Object Inspector, set the name to actSomeAction, set a desired shortcut, a caption to be uses in menu's, an imageindex if a TImageList is connected to the parent ActionList, Hint is hints are to be displayed, helpkeyword and other properties where relevant.
The most important is the OnExecute-event that will be executed if the action is triggered somehow (menu, shortcut, button).
procedure TMyForm.actSomeActionExecute(Sender: TObject);
var
f: TSomeForm;
rv: integer;
begin
f := TSomeForm.Create( nil );
f.Caption := 'SomeForm';
rv := f.ShowModal();
if rv=mrOk then
DoSomethingMeaningful();
f.Free();
end;
If you use the newly created action in a TMenuItem of a TMainMenu or TPopupMenu you are ready to go.