- To see an example, click Save.
- When you are asked to save, click Cancel
A menu that is disabled is not accessible at the moment. This kind of menu depends on another action or the availability of something else.
To see an example, click Edit and notice Undelete, Redo, Cut, Copy, and
Paste
A menu with three dots means an action is required in order to apply its
setting(s). Usually, this menu would call a dialog box where the user would have to make a decision.
As an example, on the main menu, click Tools and click Editor Options…
- On the Editor Options dialog, click OK
A menu with an arrow holds submenu. To use such a menu, position the mouse on it to display its submenu.
For example, on the main menu, click Edit and position the mouse on Flip
Children
- To dismiss the menu, click Edit
- To dismiss the menu, click Edit again
|
This book uses the -> arrow for the menu requests.From now on, in this book, |
|
Request |
Means |
| Edit -> Copy |
Click Edit then click Copy |
|
View -> Toolbars -> Custom |
Click View, position the mouse on Toolbars, and then click Custom |
- Notice that on the main menu (and any menu), there is one letter underlined on each word. Examples are F in File, E in Edit, etc. The underlined letter is called an access key. It allows you to access the same menu item using the keyboard. In order to use an access key, the menu should have focus first. The menu is given focus by pressing either the Alt or the F10 keys.
To see an example, press Alt
- Notice that one of the items on the menu, namely File, has its border raised. This means the menu has
focus
- Press p and notice that the Project menu is expanded
- When the menu has focus and you want to dismiss it, press Esc.
For example, press Esc
- Notice that the Project menu has collapsed but the menu still has
focus
- Press f then press o. Notice that the Open dialog displays
- On most or all dialog boxes that have either an OK, Open, or Save buttons, when you press Enter, the OK, Open, or Save button is activated. On the other hand, most of those dialog boxes also have a Cancel button. You can dismiss those dialogs by clicking Cancel or pressing Esc.
As an example, press Esc to dismiss the Open dialog
- On some menu items, there is a combination of keys we call a shortcut. This key or this combination allows you to perform the same action on that menu using the keyboard.
If the shortcut is made of one key only, you can just press it. If the shortcut is made of two keys, press and hold the first one, while you are holding the first, press the second key once and release the first key. Some shortcuts are a combination of three keys.
To apply an example, press and hold Ctrl, then press S, and release
Ctrl
- Notice that the Save As dialog box opens. To dismiss it, press Esc.
A menu of a computer program is a list of actions that can be performed on that application. To be aware of these actions, the list must be presented to the user upon request.
A menu is considered a main menu, when it carries most of the actions the user can perform on a particular application. Such a menu is positioned on the top section of the form in which it is used. By design, although a main menu is positioned on a form, it actually belongs to the application.
A main menu is divided in categories of items and each category is represented by a word. Here is an example:
On the C++ Builder's IDE, the categories of menus are File, Edit, Search, View, etc. To use a menu, the user first clicks one of the words that displays on top. Upon clicking, the menu expands and displays a list of items that belong to that category. Here is an example where the View menu of WordPerfect was clicked therefore got expanded:
There is no strict rule on how a menu is organized. There are only suggestions. For example, actions that are related to file processing, such as creating a new file, opening an existing file, saving a file, printing the open file, or closing the file usually stay under a category called File. In the same way, actions related to viewing documents can be listed under a View menu.
To create a main menu in the VCL, you can use the TMainMenu class. In C++ Builder, the main menu is created using the MainMenu control
. To get it, on the
Standard section of the
Tool Palette, click the MainMenu button
and click on the form. It does not matter where you drop the MainMenu icon because it will not be seen what the program runs.
To create the list of items that belong to the menu object, open the Items property. This would display a window specially equipped for creating a main menu.
C++ Builder greatly simplifies the creation of a menu by providing menu templates. A menu template is an already created menu that you can simply select and add to your application. To use one of these, right-click the Menu Designer window and click Insert From Template:
C++ Builder provides already made menus for file, edit, and help processing:
You can still create a menu manually either without using the template or to complete the template. To create a menu category, on the Menu Designer window, click the top line and, on the Object Inspector, click Caption, type a word or a group of words and press Enter or click somewhere else.
On the menu items, a letter on each menu is underlined. This letter allows the user to access the menu using a keyboard. For example, if the letter e is underline in a File menu as in File, the user can access the File by pressing the Alt then the E keys.
A shortcut is a key or a combination of keys that the user can press to perform an action that would also be performed using a menu item. When creating a menu using the Menu Designer window, on the Object Inspector, you can specify a shortcut using the Shortcut property.
|
Practical
Learning: Creating a Main Menu
|
|
- Start a new project with the default form
- On the Tool Palette, click the Standard property sheet. Click the MainMenu button
and click on the form
- On the form, double-click the MainMenu1 icon
- As the first item is selected, on the Object Inspector, click Caption, type
&Staff and press
Enter
- On the Menu Designer window, click Staff and click the empty box under
Staff
- Type &New Hire
- On the Object Inspector, click ShortCut. Click the arrow of the ShortCut property and select Ctrl + N
- On the Menu Designer window, click the item under New Hire
- On the Object Inspector, click Caption and type &Records
- Using the Object Inspector, set the ShortCut to Ctrl + R
- On the Menu Designer window, click the item under Records and on the Object Inspector, click
Caption
- Type Time &Sheet... and on the Object Inspector, specify the ShortCut as Ctrl + M
- On the Menu Designer window, click Records and press Insert
- On the Object Inspector, click Caption and type Searc&h...
- To add a separator, click the first empty line under Time Sheet. On the Object Inspector, click Caption, type - and press Enter
- Click the empty item under the previously added separator line, type E&xit and press Enter
- To move the Search item, on the Menu Designer window, click and drag Search down:

- When the Time Sheet item is highlighted, release the mouse
- To start a new menu category, click the item on the right side of Staff
- On the Object Inspector, click Caption, type &Books and press Enter
- Click Books and click the empty item under it
- Type &New and press Enter
- Type Show All &Titles and press Enter
- To create a submenu, click New and press Ctrl and the right arrow key
- Click the new empty item on the right side of New
- Type &Title and press Enter
- Type &Author and press Enter
- Type &Category and press Enter
- Clicking each item and using the Object Inspector, specify the shortcuts as follows:

- Click the box on the right side of Books and set its caption to &View
- Click View and click the empty box under it
- On the Object Inspector, click Caption, type &Toolbar and press Enter
- Click the box under Toolbar, type &Status Bar and press Enter
- On the Menu Designer window, click Toolbar to select it
- To put a check mark on a menu item, set the Checked property to true
- Also, for the Status Bar item, set the Checked property to true
- To move the whole View menu category, click and drag View to the left:

- When Books is highlighted, release the mouse
- Close the Menu Designer Window. Notice that a menu for the form has been created.
Throughout this book, you will find out that there are other ways or intermediary ways to create a menu, such as using the
ActionList. Consequently, there are also other ways to write code for a menu.
If you create a menu as we have just done, to write code for one of the menu items, from the Menu Designer window, you can double-click the menu item. This would open the
OnClick event of the menu item in the Code Editor and you can start writing the desired code for that item.
If you have already created the menu and you have closed the Menu Designer window, on the form, you can open the menu category and click the menu item as if you were regularly trying to use the menu. This would open the Code Editor with the
OnClick event of the menu item
|
Practical
Learning: Coding a Main Menu Item
|
|
- On the form, click Staff and click Exit
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::Exit1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
|
- Test the form. To close it, click Staff -> Exit
|
Popup and Context-Sensitive Menus |
|
A menu is considered or qualifies as popup if or because it can appear anywhere on the form as the programmer wishes. Such a menu is also referred to as context-sensitive because its appearance and behavior depends on where it displays on the form or on a particular control.
The first difference between a main menu and a popup menu is that a popup menu appears as one category or one list of items and not like a group of categories of menus like a main menu. Secondly, while a main menu by default is positioned on the top section of a form, a popup menu does not have a specific location on the form.
To use a popup menu, usually the user can right-click the section of the form or the object on which the menu is configured to appear.
A popup menu is based on the TPopupMenu VCL class. To visually create a popup menu, on the
Standard section of the
Tool Palette, click the PopupMenu button
and click on the form. Once you have a PopupMenu object, you can double-click it, which would open the Menu Designer.
In the Menu Designer window, to create a menu, click an empty item and, on the Object Inspector, type a text on the Caption field. Everything on an item of a popup menu can be configured like an item of a main menu. Unlike a main menu, a popup menu provides a single list of items. If you want different popup menus for your form, you have two options. You can create various popup menus or programmatically change your single popup menu in response to something or some action on your form.
There is nothing particularly specific with writing code for a popup menu item. You approach it exactly as if you were dealing with a menu item of a main menu. You can write code for an item of a popup menu independent of any other item of a main menu. If you want an item of a popup menu to respond to the same request as an item of a main menu, you can write code for one of the menu items (either the item on the main menu or the item on the popup menu) and simply call its OnClick() event in the event of the other menu item.
|
Practical
Learning: Creating a Popup Menu
|
|
- On the Standard section of the Tool Palette, click the PopupMenu button
and click on the form
- On the form, double-click the PopupMenu button
- On the Menu Designer window, as the first item is select, on the Object Inspector, click Caption, type &Font... and press Enter
- Click the empty box under Font to select it. Type &Options and press
Enter
- Click the empty box under Intermediate. Type &Properties and press
Enter
- Click the empty box under Properties and, on the Object Inspector, click Caption, type - and press
Enter
- Set the caption of the last item to Finis&h
- While still in the Menu Designer window, click Finish
- On the Object Inspector, click the Events tab and click the OnClick field
- Click the arrow of the right field and select Exit1Click
- Close the Menu Designer window
- Click an empty area on the form to select the form
- On the Object Inspector, click the Properties tab and click PopupMenu
- Click the arrow of the PopupMenu property and select PopupMenu1
- Test the form. Right-click in the middle of the form and click Finish
A toolbar is a Windows control that allows the user the perform some actions on a form by clicking a button instead of using a menu. What a toolbar provides is a convenient group of buttons that simplifies the user's job by bringing the most accessible actions as buttons so that, instead of performing various steps to access a menu, a button on a toolbar can bring such common actions closer to the user:
Toolbars usually display under the main menu. They can be equipped with buttons but sometimes their buttons or some of their buttons have a caption. Toolbars can also be equipped with other types of controls.
There are various ways you can create a toolbar. The simplest and the most common means of getting a toolbar is by using the
TToolBar VCL class. To create a toolbar, on the Win32 tab of the Tool Palette, click ToolBar
and click on the form. By default, a toolbar is positioned on the top section of the form because it takes the
alTop value of the Align property.
Like a form, a toolbar is only a container and does not provide much role by itself. To make a toolbar efficient, you should equip it with the necessary controls. The most common control used on a toolbar is a button. To add a button to a toolbar, right-click the toolbar and click New Button. The new button would appear empty. A button on a toolbar is a rectangular object with a picture on top. The picture on the button should suggest what the button is used for but this is not always possible. Providing a picture is more important. The easiest way to provide pictures for your toolbar is by creating an image list and associating it with the toolbar. If a toolbar is given an image list, whenever you right-click the toolbar and click Add Button, the image corresponding to the index of the list would display on the new button. You can keep adding buttons in this fashion.
A separator is a line that separates buttons (or controls) as groups of objects on a toolbar. To create a separator, you can right-click the toolbar and click New Separator.
As a toolbar can be equipped with various types of controls, there are various types of buttons you can place on a toolbar. The types of buttons can be configured using the Style property on the Object Inspector.
|
Practical
Learning: Creating a Toolbar
|
|
- To create a new popup menu, on the Standard section of the Tool Palette, double-click PopupMenu

- Using the Object Inspector, change the name of the new popup menu to mnuNewPopup
- Double-click the mnuNewPopup icon. Create a menu with the &Staff,
&Customer, &Book, and &Author

- Then close the Menu Designer window
- To create a new popup menu, on the Standard section of the Tool Palette, double-click PopupMenu

- Change its name to mnuViewPopup and double-click it
- Create two menu items as &Toolbar and &Status Bar
- Set the Checked property of each to true then close the Menu Designer window
- To create a new toolbar, on the Tool Palette, click the Win32 tab
- Click the ToolBar button and click on the form
- On the Object Inspector, set the Flat property to true
- Set the Height to 25
- Set the Images to imgMainMenu
- Change the name of the toolbar to tbrStandard
- To add a new button, right-click the toolbar and click New Button
- Right-click the toolbar again and click New Button
- Right-click the toolbar again and click New Button
- While the new button is still selected, on the Object Inspector, change its ImageIndex to 3 instead of 2
- Right-click the toolbar again and, this time, click New Separator
- Right-click the toolbar again and click New Button
- While the new button on the toolbar is still selected, on the Object Inspector, click Style and set its value to tbsDropDown
- Still on the Object Inspector, click DropDownMenu and set its value to mnuNewPopup
- Click an empty area on the toolbar to select it
- On the Object Inspector, set its PopupMenu to mnuViewPopup

The controls on a toolbar are programmed with regards to their own kind. This means that the coding of a control of a toolbar is not directly related to the toolbar: the toolbar is simply a host to the controls positioned on it.
If the control whose code you want to write is a button, you can simply proceed with the
OnClick event of the button. If the button should perform the same action as a menu item, and if you have already written code for the menu item, you can simply select its Click event in the
OnClick event field of the toolbar button. Otherwise, you can write completely independent code for a button on a toolbar.
|
Practical
Learning: Coding a Toolbar
|
|
- On the main menu of the form, click View -> Toolbar
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::Toolbar1Click(TObject *Sender)
{
tbrStandard->Visible = !tbrStandard->Visible;
Toolbar1->Checked = !Toolbar1->Checked;
}
//---------------------------------------------------------------------------
|
- On the form, double-click the mnuViewPopup icon to open the Menu Designer window
- Click Standard and, using the Object Inspector, set the OnClick event of Standard to Toolbar1Click
- Test the form. Right-click the toolbar and click Standard. On the main menu of the form, click View -> Standard

- After viewing the form, close it.
A status bar is a Windows control that usually displays on the bottom section of a form or the container that is hosting it. It is used to display short pieces of information to the user. A status bar can be a simple long bar that covers the whole bottom section of a form. As such, a status bar can be considered one long panel. A status bar in based on the TStatusBar VCL class.
To create a status bar, on the Win32 tab of the Tool Palette, click the StatusBar button and click on the form. As soon as you click the form, the control would be positioned on the bottom section of the host control. Most of your status bars will be created on, or hosted by, a form but you can add a status bar to any control that can serve as a parent for other controls.
|
Characteristics of a Status Bar |
|
A newly added status bar is made of a long bar that assumes an alBottom value for the Align property. By default, a new status bar is made of a single bar, called a simple panel. On the status bar's panel, you can display various types of text such as short messages informing the user about some things that are going on. If you plan to use a single panel on your status bar, on the Object Inspector, you should set the
SimplePanel property to true.
If the SimplePanel of a StatusBar control has a value of true, you can use the
SimpleText property to display a string on the status bar. You can specify such text at design time by typing a string in the value section of the
SimpleText property. When the form runs, such a string would permanently display on the status bar:
You can also programmatically display or change the string that a status bar displays. To do this, simply assign the desired string to the
SimpleText property of the StatusBar control. In the following example, a different string displays on the status bar depending on if the user double-clicked the form or right-clicked it:
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDblClick(TObject *Sender)
{
StatusBar1->SimpleText = "The form is already active";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if( Button == mbRight )
StatusBar1->SimpleText = "There is no popup menu for this form";
}
//---------------------------------------------------------------------------
|
Practical
Learning: Creating a Status Bar
|
|
- Click an empty area on the form to select it
- On the Tool Palette, click the Win32 property sheet
- Double-click the StatusBar button

- While the new control is still selected, on the Object Inspector, click Name and type DefaultStatusBar and press Enter
- On the form, click View -> Status Bar and implement its Click event as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::StatusBar1Click(TObject *Sender)
{
DefaultStatusBar->Visible = !DefaultStatusBar->Visible;
StatusBar1->Checked = !StatusBar1->Checked;
}
//---------------------------------------------------------------------------
|
- On the form, click the newly added status bar. On the Object Inspector, set its SimplePanel property to
true
- Find and double-click the mnuViewPopup
- On the Menu Designer window, click Status Bar. On the Object Inspector, click the Event tab and, in the OnClick event, select StatusBar1Click
- Click an empty area on the form to select the form
- On the Object Inspector, set the value of the ShowHint property to true
- On the form, click an empty area on the toolbar and, on the Object Inspector, set the ShowHint property to
true
- Press F12 to display the Code Editor
If the Class Explorer is not displaying, on the main menu, click View -> ClassExplorer
In the Class Explorer, expand everything
- In the Class Explorer, right-click TForm1 and click NewMethod...
- In the Method Name edit box, type ShowToolTips
- In the Arguments edit box, type TObject* Sender
- Set the Function Result to void
- Click the Private radio button and the __fastcall check box

- Click OK and implement the function as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::ShowToolTips(TObject* Sender)
{
DefaultStatusBar->SimpleText = Application->Hint;
}
//---------------------------------------------------------------------------
|
- Press F12 to display the form
- Double-click in the middle of the form and implement its OnCreate event as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Application->OnHint = ShowToolTips;
}
//---------------------------------------------------------------------------
|
- Press F12 to display the form
- On the form, double-click the MainMenu1 icon
- In the Menu Designer window, click New Hire
- On the Object Inspector, click Hint and type Used when hiring a new employee
- In the same way, click each menu item and set their Hint as follows:
|
Menu Item |
Hint |
|
New Hire |
Used when hiring a new employee |
|
Records |
Display the records of all employees |
|
Search |
Search an employee in our records |
|
Time Sheet |
Fill out a time sheet |
|
Exit |
Quit the application |
|
Toolbar |
Toggles the toolbar |
|
Status Bar |
Toggles the status bar |
|
Show All Titles |
Display information on all books |
|
Title |
Register a new book |
|
Author |
Register a new author |
|
Category |
Create a new category |
- Close the Menu Designer window
- On the toolbar, click the first (left) button
- On the Object Inspector, click Hint, type
New Employee | Used when hiring a new employee and press Enter
- Click the second button on the toolbar and set its Hint to
Records|Display the records of all employees
- Set the Hint of the third button to Category | Create a new category
- Set the Hint of the fourth button to New Book|Create a record for a new book
- Press F9 to test your form
Instead of a long unified bar, a status bar can be divided in sections each serving a specific purpose. A section of a toolbar is called a panel. To use a more elaborate status bar, you must set its
SimplePanel property to false.
To create different panels for a status bar, on the form, you can double-click the StatusBar control. Alternatively, after selecting the control on the form, on the Object Inspector, you can click the ellipsis button of the Panels field. Once in the Panels window, you can click the Add New button. You can also right-click in the Panels window and click Add. You can also press Insert. Either of these actions performed for the first time would create a formal panel for the status bar. At this time, instead of using the
SimpleText property of the status bar, you can refer to the Panels collection of the
TStatusBar class.
If you want to use more than one section on a status bar, you must divide the status bar in as many sections as necessary. To do this, you can use the Add New button or Insert key to create each subsequent section. If you create a section by mistake or do not need it anymore, select it in the Panels window and either click the Delete Selected button or press Delete. You can also right-click an undesired item and click Delete on the popup menu.
The panels are added incrementally as you insert them. If you create more than one panel but do not like their sequence, you can rearrange them using the arrow buttons on the toolbar of the Panels window. You can also right-click an item and use the popup menu to move an item.
A status bar equipped with different sections is a collection or array of panels. Each panel belongs to an array of Items. Based on this array, each panel can be configured independently of the other(s). In fact, the main thing that unites the panels is their belonging to the same parent object: the status bar control. To access a particular panel of the status bar, you can refer to it using its index in the Items array. The first panel has an Items index of 0, the second has an index of 1, etc. For example, imagine you have a status bar with four panels. To access the 3rd panel, you can refer to it using StatusBar->Panels->Items[2]. You can specify the individual characteristics of each panel.
After creating or adding a new panel, it assumes a default length of 50 pixels. The length of a panel is specified using the Width property. The Width of panels is directly related to the panel and can be dependent on the other panels.
The most common item displayed on a panel is a string. For a status bar panel, the string to display is defined by the Text property.
If you plan to use something else than a string to display on a panel, you can specify this using the Style property. The default value of a panel's Style is
psText which indicates that the panel is used to display text. Instead of text, you can draw on the panel after setting the Style value to
psOwnerDraw.
By default, the text on a panel aligns to the left as a normal text of a paragraph does. The alignment of text is controlled by the Alignment property that provides three possibilities:
taLeftJustify, taCenter, taRightJustify.
By default, the text of a panel in sunken into the panel. This appearance of text is controlled by the Bevel property. Its default value is
pbLowered. If you want the panel's surface to be raised, set it Bevel property to
pbRaised. If you do not want any of these characteristics, sunk or raised, set its Bevel property to
pbNone.
An action list is a collection of actions that can be performed on an application. It is a convenient means of configuring actions that can occur throughout the life of an application. You saw earlier that to use menus and toolbars for different assignments, the actions had to sometimes be performed individually on the controls that shared the same functionality. An action list does not solve all problems but reduces the steps performed to find a common solution to menu items and toolbar buttons combinations.
|
Practical
Learning: Introducing Action Lists
|
|
- Start a new project with its default form
- To save it, on the Standard toolbar, click the Save All button

- Create a new folder called Notice1 and display it in the Save In combo box
- Save the unit as Main and save the project as Notice
- Set the Caption of the form to Notice
- Change the Name of the form to frmMain
- Set the ShowHint property of the form to true
- On the Win32 tab of the Tool Palette, double-click ImageList

- On the form, double-click ImageList1
- Click Add. Locate the resources that accompany this book. From the Bitmaps folder, click New and click Open
- In the same way, add the Save bitmap to the list of images
- Click OK
To create a list of actions, you can use the TActionList class. It is represented on the
Standard section of the
Tool Palette by an ActionList button
. To use it, click ActionList from the
Tool Palette and click on the form. To create the actual list, double-click the ActionList button on the form, which would open the Action List Editor window.
To simplify the creation of a list of actions, C++ Builder provides a collection of pre-configured actions. These items can appropriately respond to certain controls on your form without much code, provided the control is the type of action for which the Action item was created. To use one of the action templates, right-click anywhere in the Action List Editor and click New Standard Action. On the Standard Action Classes window, select the desired template and click OK.
|
Practical
Learning: Creating a Memo-Based Application
|
|
- On the Standard section of the Tool Palette, click ActionList
and click on the form
- While ActionList1 is still selected, on the Object Inspector, click Images and select ImageList1
- On the form, double-click ActionList1 to open the Action List Editor
- On the toolbar of the Action List Editor, click the New Action button
- While the new Action1 item is still selected, on the Object Inspector, click Name and type FileNew
- Click Caption and type &New
- Click Category and type File
- Click Hint and type New|Creates a new document
- Click Shortcut, then click the arrow of its combo box and select Ctrl + N
- In the ImageIndex combo box, select 0
- Right-click the left frame of the Action List Editor and click New Action
- While the new Action1 item is still selected, on the Object Inspector, click Caption and type &Save
- In the Category combo box, select File
- Click Name and type FileSave
- Click Hint and type Save|Saves the current document
- Set its ImageIndex to 1
- Click Shortcut, then click the arrow of its combo box and select Ctrl + S
- On the toolbar of the Action List Editor, click the arrow of the New Action button
- Click New Standard Action…
- In the Standard Action Classes dialog box, scroll down to the Internet node.
- Double-click SendMail
- Right-click the right frame of the editor and click New Standard Action…
- In the Standard Action Classes dialog box, scroll down to the File node. Click TFileOpen. Press and hold Ctrl. Then click TFileSaveAs, TFilePrintSetup, and TFileExit. Release Ctrl
- Click OK
- On the left frame of the Action List Editor, click File to display its list of related actions
- On the right frame, click FileSaveAs1 to select it. Using the Object Inspector, set its Shortcut to F12
- While the File node is still selected in the left frame, in the right frame, click FileOpen1 to select it and, on the toolbar of the editor, click the Move Up button . Click File again to see the result
- Right-click one of the frames of the editor and click New Standard Action…
- Click TEditCut. Press and hold Shift. Then click TEditDelete and release Shift
- Click OK
- Move the EditUndo1 item to be on top of the list
- Move the EditDelete1 item and place it under EditPaste1
- Close the Action List Editor window and save All
- From the Standard section of the Tool Palette, click MainMenu and click the form
- While the MainMenu1 icon is still selected, on the Object Inspector, set its Images property to ImageList1
- On the form, double-click MainMenu1 to open the Menu Editor
- Right-click the selected box on the Menu Editor and click Insert From Template…
- On the Insert Template dialog box, double-click File Menu
- Click the empty box on the right side of File to select it. Display the Insert Template dialog box again and double-click Edit Menu
- Delete Repeat, Paste Special, Go To, the separator under Go To, Links, and Object
- On the Menu Editor, click File and click New to select it
- On the Object Inspector, click the Action field and select FileNew from its combo box
- In the same way, selecting the menu items and using the Action field from the Object Inspector, associate the menu items to their corresponding actions as follows:
|
Menu Item |
Action |
|
Open… |
FileOpen1 |
|
Save |
FileSave |
|
Save As… |
FileSaveAs1 |
|
Print Setup… |
PrintSetup1 |
|
Exit |
FileExit1 |
|
Undo |
EditUndo1 |
|
Cut |
EditCut1 |
|
Copy |
EditCopy1 |
|
Paste |
EditPaste1 |
- In the Edit menu, click the separator under Paste and press Insert. Set its Action to EditDelete1
- Close the Menu Editor
- Save All
- From the Win32 tab of the Tool Palette, click ToolBar
and click an empty area on the form
- Using the Object Inspector, set the Height value to 40
- Change the Name of the toolbar to tbrStandard
- Set the ShowCaptions property to true
- Set its Image property to ImageList1
- Right-click the toolbar and click New Button. On the Object Inspector, set its MenuItem property to FileNew
- Complete the buttons as follows:
- Press F12 to display the Code Editor. In Class Explorer, expand the Classes node and TfrmMain. Right-click TfrmMain and click New Method...
- Set the Method Name to ShowHints. Specify its Argument as TObject *Sender and the Function Result to void and click
OK
- Implement the method as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmMain::ShowHints(TObject * Sender)
{
StatusBar->SimpleText = Application->Hint;
}
//---------------------------------------------------------------------------
|
- Press F12 to get back to the form. Double-click in the middle of the form and implement its OnCreate event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
Application->OnHint = ShowHints;
}
//---------------------------------------------------------------------------
|
- Press F12 to display the form and Save All
|
Action Lists Messages and Events |
|
As their name implies, the actions of a list are simply meant to perform central actions that other objects may need. To manage their behavior, they are usually implemented through a function pointer called TActionEvent. This function pointer is defined as follows:
typedef void __fastcall (__closure *TActionEvent)
(Classes::TBasicAction* Action,
bool &Handled);
This means that an event created from this function will require two arguments. The first argument, Action, is in fact a pointer to the
TBasicAction class. The TBasicAction class carries information about the action that needs to be carried. Information can be used to specify whether the action must be executed anew or only updated, whether there was a change to take into consideration or the change that occurred must be dismissed.
The Handled argument specifies how the action will be carried, whether it will execute or simply update the action.
When an action needs to be carried, the object that initiates the action fires an
OnExecute() event, which is a TActionEvent type. If the action needs to be updated, the
OnUpdate() event fires, which also is a TActionEvent type. When a change
occurs in the action list, an OnChange() event is fired. This is a TNotifyEvent type.
|
|