Home

Frame-Supporting Controls

 

 The Main Menu

 

Introduction

There are four main types of menus you will encounter.

When clicked, the behavior of a menu that stands alone depends on the actions prior to clicking it. Under the File menu, examples include Save, Close All or Exit. For example, if you click Close All, Borland C++ Builder will find whether the project had been saved already. If it were, the project would be closed; otherwise, you would be asked whether you want to save it

  1. To see an example, click Save.
  2. When you are asked to save, click Cancel
  3. 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
  4. 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…
  5. On the Editor Options dialog, click OK
  6. 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
  7. To dismiss the menu, click Edit
  8. 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
  9. 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
  10. Notice that one of the items on the menu, namely File, has its border raised. This means the menu has focus
  11. Press p and notice that the Project menu is expanded
  12. When the menu has focus and you want to dismiss it, press Esc.
    For example, press Esc
  13. Notice that the Project menu has collapsed but the menu still has focus
  14. Press f then press o. Notice that the Open dialog displays
  15. 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
  16. 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
  17. 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.

Main Menu Creation

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 Practical Learning: Creating a Main Menu

  1. Start a new project with the default form
  2. On the Tool Palette, click the Standard property sheet. Click the MainMenu button and click on the form
  3. On the form, double-click the MainMenu1 icon
  4. As the first item is selected, on the Object Inspector, click Caption, type &Staff and press Enter
  5. On the Menu Designer window, click Staff and click the empty box under Staff
  6. Type &New Hire
  7. On the Object Inspector, click ShortCut. Click the arrow of the ShortCut property and select Ctrl + N
  8. On the Menu Designer window, click the item under New Hire
  9. On the Object Inspector, click Caption and type &Records
  10. Using the Object Inspector, set the ShortCut to Ctrl + R
  11. On the Menu Designer window, click the item under Records and on the Object Inspector, click Caption
  12. Type Time &Sheet... and on the Object Inspector, specify the ShortCut as Ctrl + M
  13. On the Menu Designer window, click Records and press Insert
  14. On the Object Inspector, click Caption and type Searc&h...
  15. To add a separator, click the first empty line under Time Sheet. On the Object Inspector, click Caption, type - and press Enter
  16. Click the empty item under the previously added separator line, type E&xit and press Enter
  17. To move the Search item, on the Menu Designer window, click and drag Search down:
     
  18. When the Time Sheet item is highlighted, release the mouse
  19. To start a new menu category, click the item on the right side of Staff
  20. On the Object Inspector, click Caption, type &Books and press Enter
  21. Click Books and click the empty item under it
  22. Type &New and press Enter
  23. Type Show All &Titles and press Enter
  24. To create a submenu, click New and press Ctrl and the right arrow key
  25. Click the new empty item on the right side of New
  26. Type &Title and press Enter
  27. Type &Author and press Enter
  28. Type &Category and press Enter
  29. Clicking each item and using the Object Inspector, specify the shortcuts as follows:
     
  30. Click the box on the right side of Books and set its caption to &View
  31. Click View and click the empty box under it
  32. On the Object Inspector, click Caption, type &Toolbar and press Enter
  33. Click the box under Toolbar, type &Status Bar and press Enter
  34. On the Menu Designer window, click Toolbar to select it
  35. To put a check mark on a menu item, set the Checked property to true
  36. Also, for the Status Bar item, set the Checked property to true
  37. To move the whole View menu category, click and drag View to the left:
     
  38. When Books is highlighted, release the mouse
  39. Close the Menu Designer Window. Notice that a menu for the form has been created.

Coding a Main Menu Item

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 Practical Learning: Coding a Main Menu Item

  1. On the form, click Staff and click Exit
  2. Implement the event as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Exit1Click(TObject *Sender)
    {
    	Close();
    }
    //---------------------------------------------------------------------------
  3. 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 Practical Learning: Creating a Popup Menu

  1. On the Standard section of the Tool Palette, click the PopupMenu button and click on the form
  2. On the form, double-click the PopupMenu button
  3. On the Menu Designer window, as the first item is select, on the Object Inspector, click Caption, type &Font... and press Enter
  4. Click the empty box under Font to select it. Type &Options and press Enter
  5. Click the empty box under Intermediate. Type &Properties and press Enter
  6. Click the empty box under Properties and, on the Object Inspector, click Caption, type - and press Enter
  7. Set the caption of the last item to Finis&h
  8. While still in the Menu Designer window, click Finish
  9. On the Object Inspector, click the Events tab and click the OnClick field
  10. Click the arrow of the right field and select Exit1Click
  11. Close the Menu Designer window
  12. Click an empty area on the form to select the form
  13. On the Object Inspector, click the Properties tab and click PopupMenu
  14. Click the arrow of the PopupMenu property and select PopupMenu1
  15. Test the form. Right-click in the middle of the form and click Finish

Toolbars

 

Introduction

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 Practical Learning: Creating a Toolbar

  1. To create a new popup menu, on the Standard section of the Tool Palette, double-click PopupMenu
  2. Using the Object Inspector, change the name of the new popup menu to mnuNewPopup
  3. Double-click the mnuNewPopup icon. Create a menu with the &Staff, &Customer, &Book, and &Author
     
  4. Then close the Menu Designer window
  5. To create a new popup menu, on the Standard section of the Tool Palette, double-click PopupMenu 
  6. Change its name to mnuViewPopup and double-click it
  7. Create two menu items as &Toolbar and &Status Bar
  8. Set the Checked property of each to true then close the Menu Designer window
  9. To create a new toolbar, on the Tool Palette, click the Win32 tab
  10. Click the ToolBar button and click on the form
  11. On the Object Inspector, set the Flat property to true
  12. Set the Height to 25
  13. Set the Images to imgMainMenu
  14. Change the name of the toolbar to tbrStandard
  15. To add a new button, right-click the toolbar and click New Button
  16. Right-click the toolbar again and click New Button
  17. Right-click the toolbar again and click New Button
  18. While the new button is still selected, on the Object Inspector, change its ImageIndex to 3 instead of 2
  19. Right-click the toolbar again and, this time, click New Separator
  20. Right-click the toolbar again and click New Button
  21. While the new button on the toolbar is still selected, on the Object Inspector, click Style and set its value to tbsDropDown
  22. Still on the Object Inspector, click DropDownMenu and set its value to mnuNewPopup
  23. Click an empty area on the toolbar to select it
  24. On the Object Inspector, set its PopupMenu to mnuViewPopup
     

Toolbar Programming

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 Practical Learning: Coding a Toolbar

  1. On the main menu of the form, click View -> Toolbar
  2. Implement the event as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Toolbar1Click(TObject *Sender)
    {
    	tbrStandard->Visible = !tbrStandard->Visible;
    	Toolbar1->Checked = !Toolbar1->Checked;
    }
    //---------------------------------------------------------------------------
  3. On the form, double-click the mnuViewPopup icon to open the Menu Designer window
  4. Click Standard and, using the Object Inspector, set the OnClick event of Standard to Toolbar1Click
  5. Test the form. Right-click the toolbar and click Standard. On the main menu of the form, click View -> Standard
     
  6. After viewing the form, close it.

Status Bars

 

Introduction

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 Practical Learning: Creating a Status Bar

  1. Click an empty area on the form to select it
  2. On the Tool Palette, click the Win32 property sheet
  3. Double-click the StatusBar button 
  4. While the new control is still selected, on the Object Inspector, click Name and type DefaultStatusBar and press Enter
  5. 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;
    }
    //---------------------------------------------------------------------------
  6. On the form, click the newly added status bar. On the Object Inspector, set its SimplePanel property to true
  7. Find and double-click the mnuViewPopup
  8. On the Menu Designer window, click Status Bar. On the Object Inspector, click the Event tab and, in the OnClick event, select StatusBar1Click
  9. Click an empty area on the form to select the form
  10. On the Object Inspector, set the value of the ShowHint property to true
  11. On the form, click an empty area on the toolbar and, on the Object Inspector, set the ShowHint property to true
  12. 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
  13. In the Class Explorer, right-click TForm1 and click NewMethod...
  14. In the Method Name edit box, type ShowToolTips
  15. In the Arguments edit box, type TObject* Sender
  16. Set the Function Result to void
  17. Click the Private radio button and the __fastcall check box
     
    Add Method
  18. Click OK and implement the function as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ShowToolTips(TObject* Sender)
    {
    	DefaultStatusBar->SimpleText = Application->Hint;
    }
    //---------------------------------------------------------------------------
  19. Press F12 to display the form
  20. Double-click in the middle of the form and implement its OnCreate event as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
    	Application->OnHint = ShowToolTips;
    }
    //---------------------------------------------------------------------------
  21. Press F12 to display the form
  22. On the form, double-click the MainMenu1 icon
  23. In the Menu Designer window, click New Hire
  24. On the Object Inspector, click Hint and type Used when hiring a new employee
  25. 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
  26. Close the Menu Designer window
  27. On the toolbar, click the first (left) button
  28. On the Object Inspector, click Hint, type
    New Employee | Used when hiring a new employee and press Enter
  29. Click the second button on the toolbar and set its Hint to
    Records|Display the records of all employees
  30. Set the Hint of the third button to Category | Create a new category
  31. Set the Hint of the fourth button to New Book|Create a record for a new book
  32. Press F9 to test your form

Status Bar Panels

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.

Action Lists

 

Introduction

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 Practical Learning: Introducing Action Lists

  1. Start a new project with its default form
  2. To save it, on the Standard toolbar, click the Save All button
  3. Create a new folder called Notice1 and display it in the Save In combo box
  4. Save the unit as Main and save the project as Notice
  5. Set the Caption of the form to Notice
  6. Change the Name of the form to frmMain
  7. Set the ShowHint property of the form to true
  8. On the Win32 tab of the Tool Palette, double-click ImageList
  9. On the form, double-click ImageList1
  10. Click Add. Locate the resources that accompany this book. From the Bitmaps folder, click New and click Open
  11. In the same way, add the Save bitmap to the list of images
  12. Click OK

The List of Actions

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 Practical Learning: Creating a Memo-Based Application

  1. On the Standard section of the Tool Palette, click ActionList and click on the form
  2. While ActionList1 is still selected, on the Object Inspector, click Images and select ImageList1
  3. On the form, double-click ActionList1 to open the Action List Editor
  4. On the toolbar of the Action List Editor, click the New Action button 
  5. While the new Action1 item is still selected, on the Object Inspector, click Name and type FileNew
  6. Click Caption and type &New
  7. Click Category and type File
  8. Click Hint and type New|Creates a new document
  9. Click Shortcut, then click the arrow of its combo box and select Ctrl + N
  10. In the ImageIndex combo box, select 0
  11. Right-click the left frame of the Action List Editor and click New Action
  12. While the new Action1 item is still selected, on the Object Inspector, click Caption and type &Save
  13. In the Category combo box, select File
  14. Click Name and type FileSave
  15. Click Hint and type Save|Saves the current document
  16. Set its ImageIndex to 1
  17. Click Shortcut, then click the arrow of its combo box and select Ctrl + S
  18. On the toolbar of the Action List Editor, click the arrow of the New Action button
     
  19. Click New Standard Action…
  20. In the Standard Action Classes dialog box, scroll down to the Internet node.
  21. Double-click SendMail
  22. Right-click the right frame of the editor and click New Standard Action…
  23. 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
     
  24. Click OK
  25. On the left frame of the Action List Editor, click File to display its list of related actions
  26. On the right frame, click FileSaveAs1 to select it. Using the Object Inspector, set its Shortcut to F12
  27. 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
     
  28. Right-click one of the frames of the editor and click New Standard Action…
  29. Click TEditCut. Press and hold Shift. Then click TEditDelete and release Shift
  30. Click OK
  31. Move the EditUndo1 item to be on top of the list
  32. Move the EditDelete1 item and place it under EditPaste1
     
  33. Close the Action List Editor window and save All
  34. From the Standard section of the Tool Palette, click MainMenu and click the form
  35. While the MainMenu1 icon is still selected, on the Object Inspector, set its Images property to ImageList1
  36. On the form, double-click MainMenu1 to open the Menu Editor
  37. Right-click the selected box on the Menu Editor and click Insert From Template…
  38. On the Insert Template dialog box, double-click File Menu
  39. 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
  40. Delete Repeat, Paste Special, Go To, the separator under Go To, Links, and Object
  41. On the Menu Editor, click File and click New to select it
  42. On the Object Inspector, click the Action field and select FileNew from its combo box
  43. 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
  44. In the Edit menu, click the separator under Paste and press Insert. Set its Action to EditDelete1
  45. Close the Menu Editor
  46. Save All
  47. From the Win32 tab of the Tool Palette, click ToolBar and click an empty area on the form
  48. Using the Object Inspector, set the Height value to 40
  49. Change the Name of the toolbar to tbrStandard
  50. Set the ShowCaptions property to true
  51. Set its Image property to ImageList1
  52. Right-click the toolbar and click New Button. On the Object Inspector, set its MenuItem property to FileNew
  53. Complete the buttons as follows:
     
  54. Press F12 to display the Code Editor. In Class Explorer, expand the Classes node and TfrmMain. Right-click TfrmMain and click New Method...
  55. Set the Method Name to ShowHints. Specify its Argument as TObject *Sender and the Function Result to void and click OK
  56. Implement the method as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TfrmMain::ShowHints(TObject * Sender)
    {
    	StatusBar->SimpleText = Application->Hint;
    }
    //---------------------------------------------------------------------------
  57. 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;
    }
    //---------------------------------------------------------------------------
  58. 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.

Previous Copyright © 2005 Yevol Next