Qa

Q Pointers and references confuse me. Am I alone A Absolutely not Pointers and references are complicated and take some time to fully understand. You will probably have to work with C++ a while before you get a handle on pointers and references. Q Do I always have to delete an object that I created dynamically with the new operator A Yes and no. All objects created with new must have a corresponding delete, or the program will leak memory. Some objects, however, have parent objects that will...

Conditional Breakpoints

In the case of a conditional breakpoint, program execution is paused only when predefined conditions are met. To create a conditional breakpoint, first set the breakpoint in the Code Editor. Then choose View Breakpoints from the main menu to display the Breakpoint list dialog box. Right-click on the breakpoint for which you want to set conditions and choose Properties from the speed menu. When the Edit breakpoint dialog box is displayed, set the conditions for the breakpoint. Conditional...

Popup Menus Speed Menus

We're not quite done with our discussion of menus. In C++Builder, you can create pop-up menus as easily as you can create a main menu. A nice feature of C++Builder is that you can assign a particular pop-up menu to a component via the PopupMenu property of the component. When the cursor is placed over the component and the secondary mouse button is clicked, that pop-up will automatically be displayed. Writing event handlers for pop-up menus is exactly the same as writing event handlers for main...

The Project Manager Speedbar

The Project Manager speedbar can be used to navigate the project. Figure 10.2 shows the Project Manager speedbar buttons. Use the Add Unit button to add files to the project. When you click this button, the Add To Project dialog box is displayed. The Add To Project dialog box has file filters for the following types of files Resource script files (.rc) Binary resource files (.res) If you add files of any of these types, C++Builder will know what to do with them. For example, if you add a C...

Using Resource Files

Every Windows program uses resources. 1 Resources are the elements of a program that support the program but are not I executable code. A typical Windows program's resources include User-defined specialty resources (sound files and AVI files, for example) Resources are generally contained in a resource script file (a text file with an .rc extension), which is compiled by a resource compiler and then bound to the application's .exe file during the link phase. Resources are usually thought of as...

Common Events

As with properties and methods, there are some events that will be responded to most often. Components cover a wide variety of possible Windows controls, so each component will have individual needs. Events specific to forms are not covered here because I covered that information on Day 6. The most commonly used events are listed in Table 8.3. Table 8.3. Commonly handled component events. OnChange This event is triggered when a control changes in one way or another. Exact implementation depends...

The Project Manager Window

The Project Manager window shows you the current files in your project. To view the Project Manager, choose View Project Manager from the main menu. Figure 10.1 shows the Project Manager window for the Scratchpad program created on Day 6. The Project Manager window tells you at a glance the state of each file in the project. Files that are up-to-date are displayed in a regular font files that have been modified but have not yet been saved are shown in a bold font. This serves to remind you...

Using the Watch Properties Dialog

You use the Watch Properties dialog box when you add a watch and when you edit a watch. Figure 11.5 shows the Watch Properties dialog box as it looks when you're editing a variable called buff. The Expression field at the top of the Watch Properties dialog box is where you can enter a variable name to edit or to add to the Watch List. If you are adding a watch by selecting it from the Code Editor window, this field will already be filled in see the section titled Adding Variables to the Watch...

The Breakpoint List Window

The C Builder IDE keeps track of the breakpoints you have set in the Breakpoint list window. To view the breakpoint list, choose View Breakpoints from the main menu. The Breakpoint list window will be displayed, as shown in Figure 11.2. The Breakpoint list window has four columns. The first column, Filename, shows the filename of the source code unit in which the breakpoint is set. The second column, labeled Line, shows the line number on which the breakpoint is set. The Condition column shows...

Page Three Setting Up the Speedbar

Page three of the Application Wizard aids you in setting up a speedbar for your application. This is possibly the most useful feature of the Application Wizard not that the other features aren't useful . You can quickly lay out your speedbar using this page. Figure 9.10 shows the third page of the Application Wizard after a speedbar has been created. The list box on the left side of the page, labeled Menus, shows the four menus for which you can add buttons. When you choose one of the menus,...

Button Button Whos Got the Button

VCL contains several types of buttons that you can use in your applications. Although not all of them could be considered to be based on the standard Windows button control, I will still address all the button types here. Before we look at the specific button components, though, let's cover some of the basics. When setting the Caption property of a button, use the ampersand amp just as you would when setting the Caption property of menu items. The character after the ampersand will be...

Table Commonly used C operators

Assignment Operators Assignment x 10 Assign and sum Assign and subtract Assign and multiply Assign and divide Assign bitwise AND Assign bitwise OR Indirection operator int x y Address of operator int x amp y Increment operator x same as x x 1 Scope Indirect Direct As you can see, the list of operators is a bit overwhelming, so don't worry about trying to memorize each one. As you work with C you will gradually learn how to use all of the operators. It should be noted that in some cases an...

The Debugging Menu Items

Before we get into the details of the debugger, let's go over the menu items that pertain to the debugger. Some of these menu items are on the main menu under Run, and others are on the Code Editor speed menu. Most of these items are discussed in detail as you work through the chapter, so I'll just touch on them here so that you are at least familiar with them. Table 11.1 lists the Code Editor speed menu items that are specific to the debugger and their descriptions. Table 11.1. The Code Editor...

The CBuilder Main Menu and Toolbar

The C Builder main menu has all the choices necessary to make C Builder work. Because programming in C Builder is a highly visual operation, you may not use the main menu as much as you might in other programming environments. Still, just about anything you need is available from the main menu if you prefer to work that way. I'm not going to go over every item on the main menu here because you will encounter each item as you work through the next several chapters. The C Builder toolbar is a...

The switch Statement

The switch statement could be considered a glorified if statement. It allows you to execute one of several code blocks based on the result of an expression. The expression might be a variable, the result of a function call, or any valid C expression that evaluates to an expression. Here is an example of a switch statement fine amountOverSpeedLimit 10 break fine GoToCourt jailTime GetSentence Several parts make up a switch statement. First, you can see that there is the expression, which in this...

Radio Buttons and Check Boxes

Radio buttons and check boxes are specialized buttons but are, in the end, still buttons. I'm not going to spend a lot of time discussing these two buttons because implementing them is pretty straightforward. Both the RadioButton and CheckBox components have a property called Checked that can be used to set the check state and can be read to retrieve the current check state. The radio button is usually used in a group of buttons. A radio button typically signifies a group of options, only one...

Adding Variables to the Watch List

You can add variables to the Watch List in one of several ways. The quickest is to click on the variable name in the editor window and then select Add Watch at Cursor from the Code Editor speed menu or press Ctrl F5. The Watch Properties dialog box will be displayed, where you can either select watch options for the watch item or click OK or press Enter to accept the defaults. The watch item will be added to the Watch List. To add a variable to the watch without first locating it in the source...

The Font Property

The Font property is a major property and therefore needs to be included here, but there is not a lot that needs to be said about it. The Font property is an instance of the TFont class, and as such has its own properties. You can set the Font properties by double-clicking on the font name in the Object Inspector which will expand the Font node and show the Font properties or by invoking the Font dialog box. The Font dialog box is discussed in more detail later in the chapter in the section The...

Button Basics

The button components only have about three properties of note. The ModalResult Property The ModalResult property is used to provide built-in form closing for forms displayed with ShowModal . By default, ModalResult is set to mrNone which is defined as 0 . Use this value for buttons that are used as regular buttons on the form and that do not close the form. If you use any nonzero value for ModalResult, pressing the button will close the form and return the ModalResult value. For example, if...

Using the Watch List

When a breakpoint is hit, the Watch List will display the current value of any variables that have been added to the Watch List. If the Watch List is not currently open, you can choose View Watches from the main menu to display it. Under certain circumstances, a message will be displayed next to the variable rather than the variable's value. If, for instance, a variable is out of scope or not found, the Watch List displays Undefined symbol 'x' next to the variable name. If the program is not...

Setting and Clearing Breakpoints

To set a breakpoint, click in the editor window s gutter to the left of the line on which you want to pause program execution. A stop sign icon appears in the gutter, and the entire line is highlighted in red. To clear the breakpoint, click on the stop sign icon and the breakpoint is removed. You can also press F5 or choose Toggle Breakpoint from the Code Editor speed menu to toggle a breakpoint on or off. A breakpoint can only be set on a line that generates actual code. Breakpoints are not...

The List Box and Combo Box Components

Delphi Listbox

The ListBox and ComboBox components are also widely used. The ListBox component represents a standard Windows list box, which simply presents a list of choices that the user can choose from. If the list box contains more items than can be shown at one time, scrollbars appear to allow access to the rest of the items in the list box. 1 Some list boxes are owner-drawn list boxes. In an owner-drawn list box, the jmUL programmer takes the responsibility for drawing the items in the list box. You can...