Basic File IO

It won't be long before you are going to need the ability to read and write files in your applications. I saved this discussion for now because you needed an understanding of classes in order to understand how file input and output is handled in C++. If you are going to be doing heavy database operations with C++Builder, you might be relieved to know that you don't have to worry about dealing with reading and writing database files directly. That is all handled for you behind the scenes through...

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

Inline Functions

Normally a function only appears in the executable file once. Each section of code that uses the function calls the function. This means that program execution jumps from the point of the function call to the point in the program where the function resides. The statements in the function are executed, and then the function returns. When the function returns, program execution jumps back to the statement following the function call. 1 An inline function, as its name implies, is placed inline in...

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

The new and delete Operators

Up to this point I have been talking primarily about aspects of the C++ language that come from C. From this point on we'll be looking at features that are specific to the C++ language. The new and delete operators are two important C++ language features. As mentioned in the preceding section, memory in a C++ program is allocated dynamically using operator new. You free memory using the delete operator. Unless you have previously programmed in C, you might not appreciate the simplicity of new...

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

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

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

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

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