The Go to Address Command

The Go to Address command is also an advanced debugging tool. When your program crashes, Windows displays an error message showing the address of the violation. You can use the Go to Address command to attempt to find out where in your program the crash occurred. When you get an Access Violation error from Windows, you will see a dialog box similar to the one in Figure 11.10. A Windows message box reporting an access violation. When you see this error message, write down the address at which...

Runtime and Design Time Properties

The properties outlined in this section can be set at design time and also at runtime. Almost all of these properties can be read at runtime as well. The ActiveControl property is used to set the control that will have focus when the form is activated. For instance, you may want a particular edit control to have focus when a dialog box form is displayed. At design time the Value column for the ActiveControl property contains a list of components on the form. You can choose one of the components...

Main Window Forms

Forms are the main building block of a C++Builder application. Every GUI application has at least one form that serves as the main window. The main window form might be just a blank window, it might have controls on it, or it might have a bitmap displayed on it. In a typical Windows program, your main window would have a menu. It might also have decorations such as a toolbar or a status bar. Just about anything goes when you're creating the main window of your application. Each application is...

Pointers Welcome to My Nightmare

Pointers are one of the most confusing aspects of the C++ language. They are also one of the most powerful features of C++. My goal in this section is not to teach you the textbook definition of pointers, but rather to teach you pointers in the context of how you will use them in your C++Builder programs. So what is a pointer It's a variable that holds the address of another variable. There, that wasn't so bad, was it I wish it were that simple Because a pointer holds the address of another...

Data Types

1 In C++ a data type defines the way the compiler stores information in memory. In some programming languages you can get by with assigning any type of value to a variable For example, look at the following examples of BASIC code x -1 x 1000 x 3.14 x 457000 In BASIC the interpreter takes care of allocating enough storage to fit any size or type of number. In C++, however, you must declare a variable's type before you can use the variable int x1 -1 int x 1000 float y 3.14 long z 457000 This...

Cursors

The Cursor property controls the cursor that is displayed when the user moves the mouse cursor over the component. Windows automatically changes cursors for some components. For example, Windows changes the cursor to an I-beam when the cursor is moved over an Edit, a Memo, or a RichEdit component, to name just a few. To let Windows manage the cursor, leave the Cursor property set to crDefault. If you have specialized windows (components), you can specify one of the other cursors. When the mouse...

Debugging

The Debugging section of the C++ page of the Project Options dialog box controls how the compiler generates code for debugging sessions. This section has four options, which are explained in the following sections. (I'll discuss debugging operations in detail tomorrow.) When the Debug information option is enabled, C++Builder will generate debug information for the project. The debug information is stored in a separate file in the project's directory. The filename of the file containing the...

The Find and Replace Dialog Boxes

The Find and Replace dialog boxes provide users the capability to enter text to search for and text to replace the found text with, and a variety of search and replace options. The Find dialog box is encapsulated in the VCL component FindDialog, and the Replace dialog box is represented by the ReplaceDialog component. The Replace dialog box, which contains everything found on the Find dialog box, plus the extra replace features, is shown in Figure 8.11. Major properties of the FindDialog and...

Update

The Update button updates the project after the project source file has been modified. Normally, this button is disabled. If you manually change the project source file, the Update button is enabled and all files in the Project Manager file list will be grayed out. Clicking the Update button will ensure that all files in the project are reconciled. This button is also enabled after you change the project options. Saving the project will also resynchronize the project, and you won't need to...

View Form

The View Form button displays the form associated with the currently selected unit. The form is displayed in the Form Designer. As with the View Unit button, the View Form button will be disabled if no form exists for the selected unit. The Project Manager provides shortcuts for viewing a unit's source file or form. To view a unit's source file, double-click on the unit's filename (in the File column). To view a form, double-click on the form name in the Form column. Double-clicking on units...

Understanding Project Options

Project options are another of those things that are easy to ignore. For one thing, the defaults are usually good enough when you are just starting out. After all, who has time to worry about all those compiler linker options when you are just struggling to learn a new programming environment At some point, though, you will start to become more interested in what all those options do, and it's good to have some reference when the time comes. In this section we'll look at the Project Options...

The Project Manager Speed Menu

The Project Manager has a speed menu to aid you in project management. Many of the items on the speed menu are also available via the speedbar. Figure 10.3 shows the Project Manager speed menu. Table 10.1 lists the speed menu items along with a description of what each item does. Table 10.1. The Project Manager speed menu items. Saves the project and all source files in the project. Saves the project to the Object Repository. Creates a blank source code unit and displays the new unit in the...

Function Overloading

C++ allows you to have functions that have the same name but take different parameters. Function overloading is when you have two or more functions with the same name but with different parameter lists. Functions that share a common name are called overloaded functions. On Day 11 showed you an example program which contained a function called multiply (). Not surprisingly, this function multiplied two values together. The function took two integers, multiplied them, and returned the result. But...

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...

The Microsoft Foundation Class Library

Sometime between OWL 1 and OWL 2, the Microsoft Foundation Class MFC Library was born. MFC is included as part of Microsoft's Visual C compiler package. Actually, versions of MFC ship with compilers by Symantec, Watcom, and, believe it or not, Borland there may be others as well . Typically Microsoft has not licensed the most current version of MFC to other compiler vendors Symantec and Watcom , but Borland C 5.01 included MFC version 4.1, which at the time was the latest version of MFC a newer...

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...

And Now Back to Our Program

Now you begin to see where pointers fit into the scheme of things. When you create an object dynamically, the new operator returns a pointer to the object in memory. You need that pointer to be able to do anything with the object. Figure 3.1 illustrates how the pointer points to the object in memory. Note that although the memory for the dynamically created object is allocated from heap memory, the actual pointer is a local variable and is allocated from the stack. mailingListRecord structure...

Table ios class openmode specifiers

App The file is opened and any new data will be appended to the end of ate Seek to the end of the file when the file is opened. in The file is opened for input reading . This is the default for the out The file is opened for output writing . This is the default for the binary The file is opened in binary mode. The default is to open the file in text mode. In text mode, when the file is read, carriage-return linefeed cr Lf pairs are converted to a single linefeed character lf . When the file is...

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...

Parent Color Parent CtlD Parent Font and Parent ShowHint

The ParentColor, ParentCtl3D, ParentFont, and ParentShowHint properties all work the same way, so I'll discuss them at the same time. When these properties are set to true, the component takes its Color, Ctl3D, Font, or ShowHint settings from its parent. For example, for most components the ParentFont property is set to true by default. This means the component will inherit the font that its parent is currently using. To illustrate, do this exercise 1. Create a blank form. Set the Font...

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,...

Whats this

All classes have a hidden data member called this. this is a pointer to the instance of the class in memory. A discussion on the this pointer quickly starts to look like a Who's on First comedy sketch, but I'll try anyway. Obviously this pun intended will require some explanation. First, let's take a look at how the Rect class would look if this were not a hidden data member Rect int _left, int _top, int _bottom, int _right void SetRect int _left, int _top, int _bottom, int _right private Rect...

Passing Function Parameters by Reference and by Pointer

Earlier I talked about passing objects to functions by value. I said that in the case of structures and classes, it is usually better to pass those objects by reference rather than by value. Any object can be passed by reference. This includes the primitive data types such as int and long, as well as instances of a structure or class. To review, when you pass function parameters by value, a copy of the object is made, and the function works with the copy. When you pass by reference, a pointer...

The Alignment Palette and the Alignment Dialog

It is often necessary to move or size components relative to the form or relative to one another. The Alignment Palette contains several buttons that aid in that task. The Alignment dialog box performs the same operations as the Alignment Palette, but in a different format. To display the Alignment Palette, choose View Alignment Palette from the main menu. Figure 7.l0 shows the Alignment Palette and a description of each button. Align vertical centers Center vertically in window The Alignment...

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...

Exercises

Write a Windows GUI program that displays the words Welcome to C Builder on the window when the program runs. 2. Rewrite the program you wrote in exercise 1 and change the displayed text to Hello There Hint You only have to change the Caption property of the Label component. 3. Write a Windows console-mode application that outputs This is a test to the screen. 4. Write a Windows console-mode application. In the program, declare two variables and assign values to those variables. Multiply the...

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...

View Call Stack

While your program is running, you can view the call stack to inspect any functions your program called. From the main menu, choose View Call Stack to display the Call stack window. This window displays a list of the functions that were called by your program and the order in which they were called. The most recently called function will be at the top of the window. The functions listed will be a combination of functions in your program, VCL methods, and functions contained in Windows DLLs....

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...

Give Me a Hint

The Hint property is used to set hint text for a component. The hint text has two parts. The first part is sometimes called the short hint. This is the hint text that is displayed when the user places the cursor over the component and pauses. The pop-up window that displays the hint text is called a tool tip. The second part of the hint text is sometimes called the longhint. The long hint is the optional hint text that will show in the status bar when the user moves the mouse cursor over the...

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...