RAD Studio |  |

Developing the application user interface
Collapse All
Topics

Name | Description
Adding Forms | To add a form to your project, select FileNewForm. You can see all your project's forms and their associated units listed in the Project Manager ( ViewProject Manager) and you can display a list of the forms alone by choosing ViewForms.
Adding Color, Patterns, or Pictures to Menus, Buttons, and Toolbars | You can use the Background and BackgroundLayout properties to specify a color, pattern, or bitmap to use on a menu item or button. These properties also let you set up a banner the runs up the left or right side of a menu. You assign backgrounds and layouts to subitems from their action client objects. If you want to set the background of the items in a menu, in the form designer click on the menu item that contains the items. For example, selecting File lets you change the background of items appearing on the File menu. You can assign... more
Adding Icons to Menus and Toolbars | You can add icons next to menu items or replace captions on toolbars with icons. You organize bitmaps or icons using an ImageList component.
Adding Images to Menu Items | Images can help users navigate in menus by matching glyphs and images to menu item action, similar to toolbar images. You can add single bitmaps to menu items, or you can organize images for your application into an image list and add them to a menu from the image list. If you're using several bitmaps of the same size in your application, it's useful to put them into an image list. To add a single image to a menu or menu item, set its Bitmap property to reference the name of the bitmap to use on the menu or menu... more
Adding, Inserting, and Deleting Menu Items | The following procedures describe how to perform the basic tasks involved in building your menu structure. Each procedure assumes you have the Menu Designer window open.
Adding a Cool Bar Component | Note: The TCoolBar component requires version 4.70 or later of COMCTL32.DLL. The cool bar component (TCoolBar)—also called a rebar—displays windowed controls on independently movable, resizable bands. The user can position the bands by dragging the resizing grips on the left side of each band.
Adding a Speed Button to a Panel | To add a speed button to a toolbar panel, place the speed button component (from the Additional category of the Tool palette) on the panel. The panel, rather than the form, "owns" the speed button, so moving or hiding the panel also moves or hides the speed button. The default height of the panel is 41, and the default height of speed buttons is 25. If you set the Top property of each button to 8, they'll be vertically centered. The default grid setting snaps the speed button to that vertical position for you.
Adding a Toolbar Using a Panel Component |
Adding a Toolbar Using the Toolbar Component | The toolbar component (TToolBar) offers button management and display features that panel components do not.
Adding a Tool Button | To add a tool button to a toolbar, right-click on the toolbar and choose New Button. The toolbar "owns" the tool button, so moving or hiding the toolbar also moves or hides the button. In addition, all tool buttons on the toolbar automatically maintain the same height and width. You can drop other controls from the Tool palette onto the toolbar, and they will automatically maintain a uniform height. Controls will also wrap around and start a new row when they do not fit horizontally on the toolbar.
Adding Hidden Toolbars | Toolbars do not have to be visible all the time. In fact, it is often convenient to have a number of toolbars available, but show them only when the user wants to use them. Often you create a form that has several toolbars, but hide some or all of them.
Allowing Toggle Buttons | Sometimes you want to be able to click a button in a group that's already pressed and have it pop up, leaving no button in the group pressed. Such a button is called a toggle. Use AllowAllUp to create a grouped button that acts as a toggle: click it once, it's down; click it again, it pops up. To make a grouped speed button a toggle, set its AllowAllUp property to True. Setting AllowAllUp to True for any speed button in a group automatically sets the same property value for all buttons in the group. This enables the group... more
Allowing Toggled Tool Buttons | Use AllowAllUp to create a grouped tool button that acts as a toggle: click it once, it is down; click it again, it pops up. To make a grouped tool button a toggle, set its AllowAllUp property to True. As with speed buttons, setting AllowAllUp to True for any tool button in a group automatically sets the same property value for all buttons in the group.
Assigning a Menu to a Tool Button | If you are using a toolbar (TToolBar) with tool buttons (TToolButton), you can associate menu with a specific button:
Assigning a Speed Button's Glyph | Each speed button needs a graphic image called a glyph to indicate to the user what the button does. If you supply the speed button only one image, the button manipulates that image to indicate whether the button is pressed, unpressed, selected, or disabled. You can also supply separate, specific images for each state if you prefer. You normally assign glyphs to speed buttons at design time, although you can assign different glyphs at runtime.
Assigning Images to Tool Buttons | Each tool button has an ImageIndex property that determines what image appears on it at runtime. If you supply the tool button only one image, the button manipulates that image to indicate whether the button is disabled.
Building Menus | You add a menu component to your form, or forms, for every menu you want to include in your application. You can build each menu structure entirely from scratch, or you can start from one of the predesigned menu templates. For more information about menu templates, see Using menu templates. For more information about creating a menu using the menu designer see Naming menus Naming the menu items Adding Creating submenus Adding images to menu items Viewing the menu
Common Controls and XP Themes | Microsoft has forked Windows common controls into two separate versions. Version 5 is available on all Windows versions from Windows 95 or later; it displays controls using a "3D chiseled" look. Version 6 became available with Windows XP. Under version 6, controls are rendered by a theme engine which matches the current Windows XP theme. If the user changes the theme, version 6 common controls will match the new theme automatically. You don't need to recompile the application. The VCL can now accommodate both types of common controls. CodeGear has added a number of components to the VCL to handle... more
Controlling When Forms Reside in Memory | By default, Delphi automatically creates the application's main form in memory by including the following code in the application's main entry point:
Creating and Managing Menus | Menus provide an easy way for your users to execute logically grouped commands. The Menu Designer enables you to easily add a menu—either predesigned or custom tailored—to your form. You add a menu component to the form, open the Menu Designer, and type menu items directly into the Menu Designer window. You can add or delete menu items, or drag and drop them to rearrange them during design time. You don't even need to run your program to see the results—your design is immediately visible in the form, appearing just as it will during runtime. Your code can also... more
Creating and Using Component Templates | You can create templates that are made up of one or more components. After arranging components on a form, setting their properties, and writing code for them, save them as a component template. Later, by selecting the template from the Tool palette, you can place the preconfigured components on a form in a single step; all associated properties and event-handling code are added to your project at the same time. Once you place a template on a form, you can reposition the components independently, reset their properties, and create or modify event handlers for them just as if... more
Creating Customizable Toolbars and Menus | You can use action bands with the Action Manager to create customizable toolbars and menus. At runtime, users of your application can customize the toolbars and menus (action bands) in the application user interface using a customization dialog similar to the Action Manager editor.
Creating Dynamic Menus | Dynamic menus and toolbars allow users to modify the application in various ways at run time. Some examples of dynamic usage include customizing the appearance of toolbars and menus, hiding unused items, and responding to most recently used lists (MRUs).
Creating Frames | To create an empty frame, choose FileNewDelphi ProjectsDelphi Files and double-click Frame. You can then drop components (including other frames) onto your new frame. It is usually best—though not necessary—to save frames as part of a project. If you want to create a project that contains only frames and no forms, choose FileNewApplication, close the new form and unit without saving them, then choose FileNewDelphi ProjectsDelphi FilesFrame and save the project. Note: When you save frames, avoid using the default names Unit1, Project1, and so forth, since these... more
Creating Most Recently Used Lists | A most recently used list (MRU) reflects the user's most recently accessed files in a specific application. Using action bands, you can code MRU lists in your applications. When building MRUs for your applications, it is important not to hard code references to specific numerical indexes into the Action Manager's ActionBars property. At runtime, the user may change the order of items or even delete them from the action bands, which in turn will change the numerical ordering of the index. Instead of referring to index numbering, TActionManager includes methods that facilitate finding items by action or by caption. For... more
Creating Submenus | Many application menus contain drop-down lists that appear next to a menu item to provide additional, related commands. Such lists are indicated by an arrow to the right of the menu item. Delphi supports as many levels of such submenus as you want to build into your menu. Organizing your menu structure this way can save vertical screen space. However, for optimal design purposes you probably want to use no more than two or three menu levels in your interface design. (For pop-up menus, you might want to use only one submenu, if any.)
Creating Toolbars and Menus | Note: This topic describes the recommended method for creating menus and toolbars in Windows applications. For cross-platform development, you need to use TToolBar and the menu components, such as TMainMenu, organizing them using action lists (TActionList). See Setting up action lists for details. You use the Action Manager to automatically generate toolbars and main menus based on the actions contained in your application. The Action Manager manages standard actions and any custom actions that you have written. You then create UI elements based on these actions and use action bands to render the actions items as either menu... more
Creating a Group of Speed Buttons | A series of speed buttons often represents a set of mutually exclusive choices. In that case, you need to associate the buttons into a group, so that clicking any button in the group causes the others in the group to pop up. To associate any number of speed buttons into a group, assign the same number to each speed button's GroupIndex property. The easiest way to do this is to select all the buttons you want in the group, and, with the whole group selected, set GroupIndex to a unique value.
Creating Forms Dynamically | You may not always want all your application's forms in memory at once. To reduce the amount of memory required at load time, you may want to create some forms only when you need to use them. For example, a dialog box needs to be in memory only during the time a user interacts with it.
Creating Groups of Tool Buttons | To create a group of tool buttons, select the buttons you want to associate and set their Style property to tbsCheck; then set their Grouped property to True. Selecting a grouped tool button causes other buttons in the group to pop up, which is helpful to represent a set of mutually exclusive choices. Any unbroken sequence of adjacent tool buttons with Style set to tbsCheck and Grouped set to True forms a single group. To break up a group of tool buttons, separate the buttons with any of the following: A tool button whose Grouped property is False... more
Creating Modeless Forms Such as Windows | You must guarantee that reference variables for modeless forms exist for as long as the form is in use. This means that these variables should have global scope. In most cases, you use the global reference variable that was created when you made the form (the variable name that matches the name property of the form). If your application requires additional instances of the form, declare separate global variables for each instance.
Demo Programs: Actions, Action Lists, Menus, and Toolbars | For examples of Windows applications that use actions, action lists, menus, and toolbars, refer to <InstallDrive>\Documents and Settings\All Users\Documents\RAD Studio\6.0\Demos\DelphiWin32\VCLWin32\RichEdit (Windows XP), <InstallDrive>\Users\All Users\Documents\RAD Studio\6.0\Demos\DelphiWin32\VCLWin32\RichEdit (Windows Vista). In addition, the Application wizard (FileNewOther), MDI Application, SDI Application, and Winx Logo Applications can use the action and action list objects.
Designing Toolbars and Cool Bars | A toolbar is a panel, usually across the top of a form (under the menu bar), that holds buttons and other controls. A cool bar (also called a rebar) is a kind of toolbar that displays controls on movable, resizable bands. If you have multiple panels aligned to the top of the form, they stack vertically in the order added. You can put controls of any sort on a toolbar. In addition to buttons, you may want to put use color grids, scroll bars, labels, and so on. You can add a toolbar to a form in several ways: Place... more
Determining the Order of Merged Menu Items: GroupIndex Property | The GroupIndex property determines the order in which the merging menu items appear in the shared menu bar. Merging menu items can replace those on the main menu bar, or can be inserted. The default value for GroupIndex is 0. Several rules apply when specifying a value for GroupIndex:
Developing the Application User Interface: Overview | When you open the IDE or create a new project, a blank form is displayed on the screen. You design your application's user interface (UI) by placing and arranging visual components, such as windows, menus, and dialog boxes, from the Tool palette onto the form. Once a visual component is on the form, you can adjust its position, size, and other design-time properties, and code its event handlers. The form takes care of the underlying programming details. The following topics describe some of the major interface tasks, such as working with forms, creating component templates, adding dialog boxes, and... more
Displaying an Auto-created Form | If you choose to create a form at startup, and do not want it displayed until sometime later during program execution, the form's event handler uses the ShowModal method to display the form that is already loaded in memory:
Editing Menu Items in the Object Inspector | This topic has discussed how to set several properties for menu items—for example, the Name and Caption properties—by using the Menu Designer. The section has also described how to set menu item properties, such as the ShortCut property, directly in the Object Inspector, just as you would for any component selected in the form. When you edit a menu item by using the Menu Designer, its properties are still displayed in the Object Inspector. You can switch focus to the Object Inspector and continue editing the menu item properties there. Or you can select the menu item from... more
What Happens When an Action Fires | When an event fires, a series of events intended primarily for generic actions occurs. Then if the event doesn't handle the action, another sequence of events occurs.
Handling the Screen | A global variable of type TScreen called Screen is created when you create a project. Screen encapsulates the state of the screen on which your application is running. Common tasks performed by Screen include specifying: The look of the cursor. The size of the window in which your application is running. A list of fonts available to the screen device. Multiple screen behavior (Windows only). If your Windows application runs on multiple monitors, Screen maintains a list of monitors and their dimensions so that you can effectively manage the layout of your user interface.
Hiding the Main Form | You can prevent the main form from appearing when your application starts by using the global Application variable.
Hiding Unused Items and Categories in Action Bands | One benefit of using ActionBands is that unused items and categories can be hidden from the user. Over time, the action bands become customized for the application users, showing only the items that they use and hiding the rest from view. Hidden items can become visible again when the user presses a drop-down button. Also, the user can restore the visibility of all action band items by resetting the usage statistics from the customization dialog. Item hiding is the default behavior of action bands, but that behavior can be changed to prevent hiding of individual items, all the items in... more
Hiding and Showing Toolbars | Often, you want an application to have multiple toolbars, but you do not want to clutter the form with them all at once. Or you may want to let users decide whether to display toolbars. As with all components, toolbars can be shown or hidden at runtime as needed. To show or hide a toolbar at runtime, set its Visible property to False or True, respectively. Usually you do this in response to particular user events or changes in the operating mode of the application. To do this, you typically have a close button on each toolbar. When the... more
How Actions Find Their Targets | What happens when an action fires describes the execution cycle that occurs when a user invokes an action. If no event handler is assigned to respond to the action, either at the action list, application, or action level, then the application tries to identify a target object to which the action can apply itself. The application looks for the target using the following sequence: Active control: The application looks first for an active control as a potential target. Active form: If the application does not find an active control or if the active control can't act as a target, it... more
Developing Dialog Boxes | The dialog box components on the Dialogs category of the Tool palette make various dialog boxes available to your applications. These dialog boxes provide applications with a familiar, consistent interface that enables the user to perform common file operations such as opening, saving, and printing files. Dialog boxes display and/or obtain data. Each dialog box opens when its Execute method is called. Execute returns a Boolean value: if the user chooses OK to accept any changes made in the dialog box, Execute returns True; if the user chooses Cancel to escape from the dialog box without making or... more
Importing Resource Files | You can build menus with other applications, so long as the menus are in the standard Windows resource (.RC) file format. You can import such menus directly into your project, saving you the time and effort of rebuilding menus that you created elsewhere.
Managing Layout | At its simplest, you control the layout of your user interface by where you place controls in your forms. The placement choices you make are reflected in the control's Top, Left, Width, and Height properties. You can change these values at runtime to change the position and size of the controls in your forms. Controls have a number of other properties, however, that allow them to automatically adjust to their contents or containers. This allows you to lay out your forms so that the pieces fit together into a unified whole. Two properties affect how a... more
Manipulating Menu Items at Runtime | Sometimes you want to add menu items to an existing menu structure while the application is running, to provide more information or options to the user. You can insert a menu item by using the menu item's Add or Insert method, or you can alternately hide and show the items in a menu by changing their Visible property. The Visible property determines whether the menu item is displayed in the menu. To dim a menu item without hiding it, use the Enabled property. For examples that use the menu item's Visible and Enabled properties, see Disabling menu items. In... more
Merging Menus | For MDI applications, such as the text editor sample application, and for OLE client applications, your application's main menu needs to be able to receive menu items either from another form or from the OLE server object. This is often called merging menus. Note that OLE technology is limited to Windows applications only and is not available for use in cross-platform programming. You prepare menus for merging by specifying values for two properties: Menu, a property of the form GroupIndex, a property of menu items in the menu
Using Forms | When you create a form from the IDE, Delphi automatically creates the form in memory by including code in the main entry point of your application function. Usually, this is the desired behavior and you don't have to do anything to change it. That is, the main window persists through the duration of your program, so you would likely not change the default behavior when creating the form for your main window. However, you may not want all your application's forms in memory for the duration of the program execution. That is, if you do not want all your application's... more
Moving Menu Items | During design time, you can move menu items simply by dragging and dropping. You can move menu items along the menu bar, or to a different place in the menu list, or into a different menu entirely. The only exception to this is hierarchical: you cannot demote a menu item from the menu bar into its own menu; nor can you move a menu item into its own submenu. However, you can move any item into a different menu, no matter what its original position is. While you are dragging, the cursor changes shape to indicate whether you can release... more
Naming Conventions for Template Menu Items and Event Handlers | When you save a menu as a template, Delphi does not save its Name property, since every menu must have a unique name within the scope of its owner (the form). However, when you insert the menu as a template into a new form by using the Menu Designer, Delphi then generates new names for it and all of its items. For example, suppose you save a File menu as a template. In the original menu, you name it MyFile. If you insert it as a template into a new menu, Delphi names it File1. If you insert... more
Naming Menus | As with all components, when you add a menu component to the form, the form gives it a default name; for example, MainMenu1. You can give the menu a more meaningful name that follows language naming conventions. The menu name is added to the form's type declaration, and the menu name then appears in the Component list.
Naming the Menu Items | In contrast to the menu component itself, you need to explicitly name menu items as you add them to the form. You can do this in one of two ways: Directly type the value for the Name property. Type the value for the Caption property first, and let Delphi derive the Name property from the caption. For example, if you give a menu item a Caption property value of File, Delphi assigns the menu item a Name property of File1. If you fill in the Name property before filling in the Caption property, Delphi leaves the Caption property blank... more
Opening the Menu Designer | You design menus for your application using the Menu Designer. Before you can start using the Menu Designer, first add either a TMainMenu or TPopupMenu component to your form. Both menu components are located on the Standard category of the Tool palette. A MainMenu component creates a menu that's attached to the form's title bar. A PopupMenu component creates a menu that appears when the user right-clicks in the form. Pop-up menus do not have a menu bar. To open the Menu Designer, select a menu component on the form, and then either: Double-click the... more
Organizing Actions for Toolbars and Menus | Several features simplify the work of creating, customizing, and maintaining menus and toolbars. These features allow you to organize lists of actions that users of your application can initiate by pressing a button on a toolbar, choosing a command on a menu, or pointing and clicking on an icon. Often a set of actions is used in more than one user interface element. For example, the Cut, Copy, and Paste commands often appear on both an Edit menu and on a toolbar. You only need to add the action once to use it in multiple UI elements in your application.... more
Passing Additional Arguments to Forms | Typically, you create forms for your application from within the IDE. When created this way, the forms have a constructor that takes one argument, Owner, which is the owner of the form being created. (The owner is the calling application object or form object.) Owner can be nil. To pass additional arguments to a form, create a separate constructor and instantiate the form using this new constructor. The example form class below shows an additional constructor, with the extra argument whichButton. This new constructor is added to the form class manually.
Predefined Action Classes | You can add predefined actions to your application by right-clicking on the Action Manager and choosing New Standard Action. The New Standard Action Classes dialog box is displayed listing the predefined action classes and the associated standard actions. These are actions that are included with Delphi and they are objects that automatically perform actions. The predefined actions are organized within the following classes:
Registering Actions | When you write your own actions, you can register actions to enable them to appear in the Action List editor. You register and unregister actions by using the global routines in the Actnlist unit:
Responding to Clicks | When the user clicks a control, such as a button on a toolbar, the application generates an OnClick event which you can respond to with an event handler. Since OnClick is the default event for buttons, you can generate a skeleton handler for the event by double-clicking the button at design time. For general information about events and event handlers, see Working with Events and Event Handlers and Generating a handler for a component's default event.
Retrieving Data from Forms | Most real-world applications consist of several forms. Often, information needs to be passed between these forms. Information can be passed to a form by means of parameters to the receiving form's constructor, or by assigning values to the form's properties. The way you get information from a form depends on whether the form is modal or modeless.
Retrieving Data from Modal Forms | Just like modeless forms, modal forms often contain information needed by other forms. The most common example is when form A launches modal form B. When form B is closed, form A needs to know what the user did with form B to decide how to proceed with the processing of form A. If form B is still in memory, it can be queried through properties or member functions just as in the modeless forms example above. But how do you handle situations where form B is deleted from memory upon closing? Since a form does not have an explicit... more
Retrieving Data from Modeless Forms | You can easily extract information from modeless forms by calling public member functions of the form or by querying properties of the form. For example, assume an application contains a modeless form called ColorForm that contains a listbox called ColorListBox with a list of colors ("Red," "Green," "Blue," and so on). The selected color name string in ColorListBox is automatically stored in a property called CurrentColor each time a user selects a new color. The class declaration for the form is as follows:
Reusing Components and Groups of Components | You can save and reuse work you've done with components using several tools: Configure and save groups of components in component templates. Save forms, data modules, and projects in the Object Repository. The Repository gives you a central database of reusable elements and lets you use form inheritance to propagate changes. Save frames on the Tool palette or in the Repository. Frames use form inheritance and can be embedded into forms or other frames. Create a custom component, the most complicated but most flexible way of reusing code. See Overview of Component Creation.
Saving a Menu as a Template | Any menu you design can be saved as a template so you can use it again. You can use menu templates to provide a consistent look to your applications, or use them as a starting point which you then further customize. The menu templates you save are stored in your BIN subdirectory as .dmt files.
Selecting Menu and Toolbar Styles | Just as you can add different colors and icons to individual menus and toolbars, you can select different menu and toolbar styles to give your application a comprehensive look and feel. In addition to the standard style, your application can take on the look of Windows XP, Encarta™, or a custom presentation using a coordinated color scheme. To give your application a coherent look and feel, the IDE uses colormaps. A colormap can be simple, merely adding the appropriate colors to existing menus and toolbars. Or, a colormap can be complex, altering numerous subtle details of a menu's or toolbar's... more
Setting Up Action Bands | Because actions do not maintain any "layout" (either appearance or positional) information, Delphi provides action bands which are capable of storing this data. Action bands provide a mechanism that allows you to specify layout information and a set of controls. You can render actions as UI elements such as toolbars and menus. You organize sets of actions using the Action Manager (TActionManager). You can use standard actions provided or create new actions of your own. You then create the action bands: Use TActionMainMenuBar to create a main menu. Use TActionToolBarto create a toolbar. The action bands act as containers... more
Setting Up Action Lists | Setting up action lists is fairly easy once you understand the basic steps involved: Create the action list. Add actions to the action list. Set properties on the actions. Attach clients to the action.
Setting the Appearance of the Cool Bar | The cool bar component offers several useful configuration options. The table below lists some actions you can set to change a tool button's appearance: Setting a cool button's appearance
Setting the Initial Condition of a Speed Button | Speed buttons use their appearance to give the user clues as to their state and purpose. Because they have no caption, it's important that you use the right visual cues to assist users. The table below lists some actions you can set to change a speed button's appearance: Setting speed buttons' appearance
Setting Tool Button Appearance and Initial Conditions | The table below lists some actions you can set to change a tool button's appearance: Setting tool buttons' appearance
Sharing Frames | You can share a frame with other developers in two ways: Add the frame to the Object Repository. Distribute the frame's unit (.pas) and form (.dfm or .xfm) files. To add a frame to the Repository, open any project that includes the frame, right-click in the Form Designer, and choose Add to Repository. For more information, see Using the Object Repository. If you send a frame's unit and form files to other developers, they can open them and add them to the Tool palette. If the frame has other frames embedded in it, they will have to open... more
Specifying Accelerator Keys and Keyboard Shortcuts | Accelerator keys enable the user to access a menu command from the keyboard by pressing Alt+ the appropriate letter, indicated in your code by the preceding ampersand. The letter after the ampersand appears underlined in the menu. Delphi automatically checks for duplicate accelerators and adjusts them at runtime. This ensures that menus built dynamically at runtime contain no duplicate accelerators and that all menu items have an accelerator. You can turn off this automatic checking by setting the AutoHotkeys property of a menu item to maManual. To specify an accelerator, add an ampersand in front of the appropriate... more
Specifying the Active Menu: Menu Property | The Menu property specifies the active menu for the form. Menu-merging operations apply only to the active menu. If the form contains more than one menu component, you can change the active menu at runtime by setting the Menu property in code. For example,
Switching Between Menus at Design Time | If you're designing several menus for your form, you can use the Menu Designer context menu or the Object Inspector to easily select and move among them.
Controlling Application Behavior | TApplication, TScreen, and TForm are the classes that form the backbone of all applications by controlling the behavior of your project. The TApplication class forms the foundation of an application by providing properties and methods that encapsulate the behavior of a standard program. TScreen is used at runtime to keep track of forms and data modules that have been loaded as well as maintaining system-specific information such as screen resolution and available display fonts. Instances of the TForm class are the building blocks of your application's user interface. The windows and dialog boxes in your application are based on TForm... more
Updating Actions | When the application is idle, the OnUpdate event occurs for every action that is linked to a control or menu item that is showing. This provides an opportunity for applications to execute centralized code for enabling and disabling, checking and unchecking, and so on. For example, the following code illustrates the OnUpdate event handler for an action that is "checked" when the toolbar is visible:
Using Action Lists | Note: The contents of this topic apply to setting up toolbars and menus for cross-platform development. For Windows development you can also use the methods described here. However, using action bands instead is simpler and offers more options. The action lists will be handled automatically by the Action Manager. See Organizing actions for toolbars and menus for details. Action lists maintain a list of actions that your application can take in response to something a user does. By using action objects, you centralize the functions performed by your application from the user interface. This lets you share common code for... more
Using and Modifying Frames | To use a frame in an application, you must place it, directly or indirectly, on a form. You can add frames directly to forms, to other frames, or to other container objects such as panels and scroll boxes. The Form Designer provides two ways to add a frame to an application: Select a frame from the Tool palette and drop it onto a form, another frame, or another container object. If necessary, the Form Designer asks for permission to include the frame's unit file in your project. Select Frames from the Standard category of the Tool palette and click on... more
Using Menu Templates | Several predesigned menus, or menu templates, contain frequently used commands. You can use these menus in your applications without modifying them (except to write code), or you can use them as a starting point, customizing them as you would a menu you originally designed yourself. Menu templates do not contain any event handler code. The menu templates are stored in the BIN subdirectory in a default installation and have a .dmt extension. You can also save as a template any menu that you design using the Menu Designer. After saving a menu as a template, you can use it as... more
Using the Main Form | The first form you create and save in a project becomes, by default, the project's main form, which is the first form created at runtime. As you add forms to your projects, you might decide to designate a different form as your application's main form. Also, specifying a form as the main form is an easy way to test it at runtime, because unless you change the form creation order, the main form is the first form displayed in the running application.
Using the Menu Designer Context Menu | The Menu Designer context menu provides quick access to the most common Menu Designer commands, and to the menu template options. (For more information about menu templates, refer to Using menu templates.) To display the context menu, right-click the Menu Designer window, or press Alt+F10 when the cursor is in the Menu Designer window.
Creating a Form Instance Using a Local Variable | A safer way to create a unique instance of a modal form is to use a local variable in the event handler as a reference to a new instance. If a local variable is used, it does not matter whether ResultsForm is auto-created or not. The code in the event handler makes no reference to the global form variable. For example:
Viewing the Menu | You can view your menu in the form at design time without first running your program code. (Pop-up menu components are visible in the form at design time, but the pop-up menus themselves are not. Use the Menu Designer to view a pop-up menu at design time.)
What Is an Action? | As you are developing your application, you can create a set of actions that you can use on various UI elements. You can organize them into categories that can be dropped onto a menu as a set (for example, Cut, Copy, and Paste) or one at a time ( for example, ToolsCustomize ). An action corresponds to one or more elements of the user interface, such as menu commands or toolbar buttons. Actions serve two functions: (1) they represent properties common to the user interface elements, such as whether a control is enabled or checked, and (2) they respond... more
Working at the Application Level | The global variable Application, of type TApplication, is in every VCL-based application. Application encapsulates your application as well as providing many functions that occur in the background of the program. For instance, Application handles how you call a Help file from the menu of your program. Understanding how TApplication works is more important to a component writer than to developers of stand-alone applications, but you should set the options that Application handles in the ProjectOptions Application page when you create a project. In addition, Application receives many events that apply to the application as a whole. For... more
Working with Frames | A frame (TFrame), like a form, is a container for other components. It uses the same ownership mechanism as forms for automatic instantiation and destruction of the components on it, and the same parent-child relationships for synchronization of component properties. In some ways, however, a frame is more like a customized component than a form. Frames can be saved on the Tool palette for easy reuse, and they can be nested within forms, other frames, or other container objects. After a frame is created and saved, it continues to function as a unit and to inherit changes from... more
Writing Action Components | You can also create your own predefined action classes. When you write your own action classes, you can build in the ability to execute on certain target classes of objects. Then, you can use your custom actions in the same way you use predefined action classes. That is, when the action can recognize and apply itself to a target class, you can simply assign the action to a client control, and it acts on the target with no need to write an event handler. Component writers can use the classes in the QStdActns and DBActns units as examples for... more
Using Windows Common Dialog Boxes | One of the commonly used dialog box components is TOpenDialog. This component is usually invoked by a New or Open menu item under the File option on the main menu bar of a form. The dialog box contains controls that let you select groups of files using a wildcard character and navigate through directories. The TOpenDialog component makes an Open dialog box available to your application. The purpose of this dialog box is to let a user specify a file to open. You use the Execute method to display the dialog box. When the user chooses OK in the... more

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!