TAction: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: TAction
| Old | New | Line | |
|---|---|---|---|
| 1 | + | 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. | |
| 2 | + | ||
| 3 | + | ## Example | |
| 4 | + | ||
| 5 | + | 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 [[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. | |
| 6 | + | ||
| 7 | + | The most important is the OnExecute-event that will be executed if the action is triggered somehow (menu, shortcut, button). | |
| 8 | + | ||
| 9 | + | ``` pascal | |
| 10 | + | procedure TMyForm.actSomeActionExecute(Sender: TObject); | |
| 11 | + | var | |
| 12 | + | f: TSomeForm; | |
| 13 | + | rv: integer; | |
| 14 | + | begin | |
| 15 | + | f := TSomeForm.Create( nil ); | |
| 16 | + | f.Caption := 'SomeForm'; | |
| 17 | + | rv := f.ShowModal(); | |
| 18 | + | if rv=mrOk then | |
| 19 | + | DoSomethingMeaningful(); | |
| 20 | + | f.Free(); | |
| 21 | + | end; | |
| 22 | + | ``` | |
| 23 | + | ||
| 24 | + | If you use the newly created action in a [[TMenuItem]] of a [[TMainMenu]] or [[TPopupMenu]] you are ready to go. | |
| 25 | + | ||
| 26 | + | ## See also | |
| 27 | + | ||
| 28 | + | - [[doc:lcl/actnlist/taction.html|TAction documentation]] | |
| 29 | + | - [[TActionList]] | |
| 30 | + | - [[TActionLink]] | |
| 31 | + | - [[TActionListEnumerator]] | |
| 32 | + | - [[TContainedAction]] | |
| 33 | + | - [[TCustomAction]] | |
| 34 | + | - [[TCustomActionList]] | |
| 35 | + | - [[TShortCutList]] | |
| 36 | + | ||
| 37 | + | --- | |
| 38 | + | *From the Free Pascal wiki, page "TAction", as it stood on 2020-02-29 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
