Using TActionList
使用tactionlist
Start a new application, and drop a TActionList component on the Form.
Right-click with the mouse on the ActionList1 component to get the
Action List Editor. The Action List Editor shows the action categories,
and for each action category the individual actions that are available
for the current application.
建立一个新程序, 在form上放一个tactionlist构件. 右键点ACTIONLIST1会弹出
Action List Editor(动作编辑器). 动作编辑器显示了动作种类列表和在此程序中
可以使用的每个动作种类中的每个动作.
We can define new actions, or select a number of existing (standard)
actions. The latter can be done by right-clicking with the mouse in
the Action List Editor, and selecting the New Standard Action menu:
我们可以定义新动作, 或者选择选择一系列的已有的(标准)动作. 后面的可以通过
右键点动作编辑器, 然后选择新标准动作菜单得到.
This will give us a new dialog with the (current) list of standard
actions. Note that we can select more than one action at the same
time by holding down the Ctrl key and clicking on each individual
item (see left figure below).
这会给我们一个现有标准动作列表的对话框. 注意我们可以通过按住CTRL键不放
点击需要的项目来一次选择多个动作.
After we click on OK, we return to the Action List Editor which now
shows two categories (Edit and Window) and four actions in total
(Copy, Cut and Paste for the Edit categories, and MinimizeAll for
Windows) - see right figure above.
我们点击OK后, 就回到了动作编辑器, 现在就有了两个类别(编辑和窗口)和4个动作
(编辑类的Copy, Cut 和 Paste和窗口类的MinimizeAll ).
It's now time to add some controls to the Form and connect them to
these actions.
现在我们在FORM上添加一些控件并把他们连到动作列表上.
Control Action
控件动作
Go to the Win32 tab of the component palette, and drop a ToolBar
component on the form. Right-click on it and select "New Button"
to add a new button. Repeat this until you have four buttons next
to each other on the toolbar (tip: you may want to insert a
separator between the third and fourth button).
放一个TOOLBAR构件, 右键点选择新按钮来加一个按钮. 重复以上动作添加4个按钮.
(也许你想在3/4中间加个分割按钮)
Now, click the left button, and set its Action property to EditCopy1.
Set the Action property of the second button to EditCut1, and the
third button to EditPaste1. Finally, set the Action property of the
last button to WindowMinimizeAll1.
现在, 把第一个按钮的ACTION属性设成EDITCOPY1, 2设成EDITCUT1, 3-EDITPASTE1,
最后一个设成WindowMinimizeAll1.
Before we compile and run this application, let me remind you that
we now have four fully functional toolbar buttons without having
written a single line of code. That's because we're using standard
behavior that's already been provided to us as "standard" re-usable
Actions. But it gets even better, because we can share these actions
with multiple components.
在我们编译和运行这个程序前, 我提醒你注意我们现在有了4个全功能的工具栏按钮
而不需要编写一行代码. 这就是为什么我们用标准动作, 因为它已经提供我们这些
"标准的"可以重用的动作. 不过现在更好了, 因为我们可以把这些动作共享给许多
构件.
Go back to the Standard tab of the component palette, and drop a
TMainMenu component on the Form. Double-click on it (to get into
the Menu Designer). Right-click on the Menu Designer select "Insert
from Template" and pick the Edit menu template. This gives us a
list of 10 menu items, while we only need three (Cut, Copy and
Paste), but at least it saves us some typing. You can easily remove
the menu items that you don't need, by the way.
现在让我们在FORM上放一个TMAINMENU构件. 双击它(弹出菜单设计器). 右键点菜单
设计器选"从模版中插入", 选择编辑菜单模版. 这样会提供10个菜单项, 不过我们只
需要其中的3个(Cut, Copy 和Paste), 至少节省了我们输入时间. 你可以很简单的
去掉你不需要的菜单项.
Go to the Cut1 menu item, and set its Action property to EditCut1.
Set the Action property of the Copy1 menu item to EditCopy1, and
let Paste1 point to EditPaste1. We're now almost ready to compile
and run our application, but we need one more thing. Let's drop
three normal buttons on the form (again from the Standard tab),
and connect them to EditCut1, EditCopy1 and EditPaste1 like we've
done twice before alre
选CUT1菜单项, 把它的ACTION属性设成EDITCUT1, COPY1为EDITCOPY1, PASTE1
为EDITPASTE1. 我们现在几乎可以编译运行这个程序了, 不过还需要几个步骤.
在FORM上放3个标准按钮, 把他们的ACTION属性分别设成EDITCUT1, EDITCOPY1,
和EDITPASTE1, 就象我们已经做过两次的那样.