Steve Trefethen

Steve Trefethen is a Senior Member of the Technical Staff at Reply.com. You can reach Steve here.

All opinions expressed on this website are my own and do not necessarily reflect those of my employer.

View my LinkedIn profile

Advanced Search »
Blog
All Pages
Wiki Stats
Edit

Frequently Asked Questions for ActionBands

Download the D7 ActionBands Update from Code Central%% here.

Originally Posted: April 27, 2004
Updated: May 12, 2004
Updated: March 1, 2005

NOTE: All of the fixes discussed below that were not incorporated into the D7 patch are in Delphi 2005.

NOTE: The D7.01 patch does not include the fixes addressed in the unofficial ActionBands update. Installing D7.01 will revert the ActionBands files back to the original shipping D7 files. After installing the D7.01 update you will need to reinstall the unofficial ActionBands patch which may require you to run undoabupdate.bat (included in the ActionBands update) first. I was unable to convince QA to include the TPopupActionBarEx component which did not originally ship with D7 therefore applying the D7.01 patch will break applications that use this component.

In the end, it was decided not to ship any ActionBand fixes at all in the update and require users to reinstall the unofficial patch. Additional fixes ActionBand fixes made for the D7.1 now won't be available until D9. I've learned my lesson and I'm done doing unofficial patches as QA won't support them.

I apologize for the inconvenience.

Last updated: February 6, 2003

Edit

How can I add a separator to an ActionBand?

The latest update to ActionBands adds a new mechanism to add separators to ActionBands. The Customize dialog now has a button at the bottom that you can simply drag and drop to create separators on any ActionBand. To manually insert a separator on a TActionToolBar:

If you already have an ActionToolBar with items on it:

  1. Click an item on one of the ActionToolbars and use the arrow keys to select where want the separator.
  2. Press the Insert key, this adds a new item to the bar
  3. Set its Caption to a "-"

To insert a separator on a TActionMainMenuBar:

  1. Click one of the top level menus
  2. Use the keyboard/mouse to find the position where you want the separator
  3. Press the "-" key to insert the separator

An alternative is to use the Object Treeview and navigate within the TActionManager.ActionBars node to find where you a separator, add a new item and set its Caption to a dash "-".

Additionally, once you have an item selected on a ActionBand at design time you can hold the control key down and use the arrows to change that items position.

Also found on http://groups.google.com by searching for: %green%actionband separator

Edit

How can I make an Outlook style ActionToolBar?

See http://www.geocities.com/delphihelp/info/ABExpressTutorial.htm

Also found on http://www.google.com by searching for: actionband outlook style

Edit

How to you create submenus on a TActionMainMenuBar?

Here is an example of how to create a submenu on a TActionMainMenuBar:

  1. Select File | New | Application
  2. Drop the following components:
*TActionManager *TActionMainMenuBar
  1. Double click the TActionManager component to open the Customize dialog
  2. Press Ctrl-Insert to display the Standard Action Dialog (or click dropdown on the new action button and select New Standard Action)
  3. Select all of the File and Edit category actions and click OK
  4. Click and drag the File category onto the TActionMainMenuBar

You can now create a submenu as follows:

  1. Click and drag the Edit category onto the File item of the ActionMainMenuBar, it will open and you can drop it onto the File menu to create an Edit submenu
  2. Click the File item and use the keyboard to scroll to the location of where you want a submenu then press Insert to add a new item then press Ctrl-Right arrow to create a submenu

Also found on http://groups.google.com by searching for: actionband create tactionmainmenubar submenu

Edit

What keys can I use to edit ActionBand menus in the IDE?

You can use the followings keys on a TActionMainMenuBar at design time in the Delphi/BCB IDE:

||border=1 cellspacing=0 cellpadding=2 ||Keystroke || Function || ||Insert ||inserts a new item || ||Ctrl-Right ||on a new item to create a submenu || ||Ctrl-Up/Ctrl-Down ||move an item up or down || ||Home ||selects the first item on the menu || ||End ||select the last item ||

Also found on http://groups.google.com by searching for: %green%key IDE actionband

Edit

How can I implement a Most-Recently-Used file menu?

I've written a demo that illustrates how to implement a most-recently-used menu using ActionBands which you can download here. (Mirror site) The demo also includes code to create an Open button on a toolbar with a dropdown containing the list of recently used files.

Also found on http://www.google.com by searching for: actionband create tactionmainmenubar submenu

Edit

How can I create a dropdown button on a TActionToolBar?

To create a ActionToolBar button that has a dropdown menu do the following:

  1. On a form at design-time in the IDE drop a TActionManager and a TActionToolBar
  2. Double click the ActionManager to display the Customize dialog
  3. Add a new action to the ActionManager
  4. Drag the new action onto the TActionToolBar
  5. Select View | Object Treeview
  6. Navigate to the node Form1\ActionManager1\ActionBars\0 - ActionBar -> ToolActionBar1\Items\0 - ActionClient1\Items
  7. Right click and add new items to this node

This will create a dropdown button that has items which currently do nothing. Add new actions to the ActionManager and assign the Action property of the new nodes to build your dropdown menu.

!!!!Do ActionBands support MDI applications? Yes. See the Window property of TActionMainMenuBar.

!!!!Can I create my own custom ActionBand controls? Absolutely. ActionBands are very extensible and provide amply opportunity for people to create custom actionband controls.
  1. Create a control (or descendant of an existing control) that is able to connect to an action such that when the control is changed the action will cause "something" (whatever you want to occur) to happen.
  2. Create a TCustomActionControl that will wrap your control for usage on an ActionBand.
  3. Create an action that can link to your specific control. In the example above the list actions (TStaticListAction and TVirtualListAction) both know how to work with a combobox.
  4. Create a descendant of TCustomActionToolbar and override GetControlClass and look for your specific action class and return your new control class so that the correct kind of control is created.

This information can also be found searching http://groups.google.com for: create actionband control

Edit

Can I modify ActionBands dynamically at runtime?

Absolutely. In fact, I've created a component called TActionManagerHelper that makes this easy to do as well as a demo that illustrates dynamically modifying ActionBands to implement a most-recently-used File menu. If you are using D7 then all of the functionality of the ActionManager Helper component has been folded into TActionManager so this component is not necessary if you are using D7.

Edit

Are there any alternative style actionbands available?

These styles are now included with Delphi 7.0. For Delphi 6.0, I've created two additional menu styles. One style implements menus and toolbars that appear similar to Microsoft Office XP and the other style mimics that of Microsoft Encarta. You can obtain the code to both of these styles here. Look for XP and Encarta-style ActionBand Menus and Toolbars. Click here for some examples of ActionBands styles D7.

!!!!Is there any way to specify what the disabled Image should look like? While there currently (in D6) is no direct way to change the drawing of the disabled image you could take over the drawing yourself fairly easily. For example, if you would like to change the drawing for a toolbar button you could do the following:
  1. Create a descendant of the control you want to change (ex TCustomButtonControl)
  2. Override its DrawGlyph method and draw the glyph however you'd like
  3. On your ActionBand hook the OnGetControlClass event and return your new control class.

Now, when the ActionBand goes to create controls it will create your new control rather than the default control.

In fact, you could even extend the TCustomActionManager to create TActionClientItems that have a DisabledImageIndex property which you could then use with the control you just created above. To do this you would need to do the following:

  1. Create a descendant of TActionClientItem and simply add a DisabledImageIndex property
  2. Create a descendant of TCustomActionManager (or TActionManager if you like) and override GetActionClientItemClass method to return the class you created in step 1.

Then at designtime your property will show up. The controls won't be your custom controls until runtime which is fine since they all draw enabled at designtime anyway.

Edit

ActionBand changes made at design-time in the IDE are not showing up at runtime?

ActionBand changes made in the IDE may not appear at runtime because the ActionManager's Filename property has been set. In order to store usage information and menu/toolbar layout information the ActionManager must save this information to disk. When you restart the application the ActionManager reloads this file and restores the ActionBands to their previous state causing the appearance of changes made in the IDE not being reflected at runtime. To avoid this situation you must either remember to delete this settings file before running your application from the IDE or avoid setting the ActionManager's Filename property until you are ready to deploy your application. When the ActionManager's Filenname property is not set then what you see in the IDE should be exactly what you see at runtime.

Edit

How can I turn off the captions of the Items on an TActionToolBar?

  1. File | New | App
  2. Drop TActionManager, TActionToolBar, TImageList
  3. Set TActionManager.ImageList = ImageList1
  4. Open the ActionManager Customize dialog and add all of the Edit actions
  5. Drag/drop the Edit category onto the TActionToolbar
  6. View the Object Treeview and Expand the ActionManager node
  7. Then the treeview as follows ActionBars->"0 - ActionBar->ActionToolBar1"->Items
  8. You should see all of the Edit items on your ActionToolbar, multi-select them (click the first item and hold the shift key down and use the down arrow key).
  9. In the Object Inspector set ShowCaption = False.
  10. Run the application, and notice that only the Select All action's Caption is displayed since it has no glyph.

At this point you can selectively turn on/off captions using the ShowCaption property for each item.

This answer could also have been found here by searching http://groups.google.com for: %green% caption items tactiontoolbar

For additional information use the above search and refer to the thread D6 TActionManager, TActionMainMenuBar and TActionToolBar

NOTE: In order to be able to set ShowCaption to False the item must have an image assigned otherwise you should use the Visible property to control whether or not the item appears on the ActionBand.

Edit

How do you disable a top level Menu Item?

Since the controls can be deleted by the user at runtime you don't have direct access to them, however in D7 the TActionManager has methods to allow you to find an manipulate items on ActionBands. For D6, I've written a TActionManagerHelper component that makes it easy to find and work with items dynamically at runtime. You can download this component from my website. Once you have this component you can use the following code to control the Enabled state of a top level menu item (or any control on any ActionBand for that matter, depending of course that its associated action doesn't override you).

var I: TActionClientItem; begin // In this case the Item's Caption is '&test' I := ActionManagerHelper1.FindItemByCaption('&test'); if Assigned(I) then I.Control.Enabled := not I.Control.Enabled; end;

This answer could also have been found here by searching groups.google.com for disable top level menu TActionMainMenuBar

Edit

How can I hide actions from appearing in the ActionManager's Customize dialog

Use the TCustomizeDlg component and add a new action that calls CustomizeDlg.Show. Then use the OnShow/OnClose events of the TCustomizeDlg to remove/restore the actions you don't want to appear in the dialog. To remove an action from an action list simply set its ActionList property to nil. To "put it back" into the actionlist simply reassign its ActionList property.

This answer could also have been found here by searching http://groups.google.com for: customize actionmanager hide

Edit

How can I create Actionband items in code?

In order to create ActionBands entirely in code you need to be comfortable working with TCollection since TActionManager relies heavily on collections.

Here is an example of how to add a single item to a new ActionBar of a TActionManager.

=beautify delphi procedure TForm1.FormCreate(Sender: TObject); var AnAction: TAction; begin // Setup the new action AnAction := TAction.Create(Self); AnAction.Caption := 'Test'; AnAction.Category := 'New Category'; // Should assign some event handler if it's just a TAction // AnAction.OnExecute := AnActionExecute; // "Add" the action to the action manager AnAction.ActionList := ActionManager1; // Add a new TActionBarItem, you could use an existing one ActionManager1.ActionBars.Add; // Manually a new TActionClientItem and assign the new action to it with ActionManager1.ActionBars0.Items.Add do Action := AnAction; end;
Copyright © 2006-2010 Steve Trefethen. Some rights reserved.
Except where otherwise noted, content on this work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
Powered by: ScrewTurn Wiki version 2.0.36