dBASE for Windows,
A Product Review
(Part 3)
Software Review by Mike Bianchi

TOC

Last month, in part 2 of this review, I talked about Queries, Forms and Reports. My original intention was to include Tools in that installment, however, that section was cut because Cynthia needed the space.

This third installment will pick up at that point.

Tools

Expression Builder: An expression is one or more dBASE elements that evaluate to a single value. Elements include field names, constants, functions, operators, variables or array elements. The Expression Builder is accessed through the menu by selecting Edit|Build Expression or by clicking the Tool button next to any field that accepts an expression in a dialog box.

Expression Builder Figure 1: Expression Builder

The Expression box is where the expression is assembled as the elements are added. Below the Expression box are three lists labeled Category, Type (or Table) and Paste. The Category lists the types of elements that can be used to make up an expression. The center box lists the choices for the category selected in the first box. If the selected category is 'Field', the center box is labeled 'Table' and lists the tables that are open. The Paste box lists the actual expression elements of the category and type selected, selecting an element from this list inserts it into the expression.

The Safety Net check box adds an additional level of assistance that will be especially appreciated by the inexperienced user. When the Safety Net is selected, you can only select elements from the Paste list and as each element is added it is checked for correct syntax. Placeholders representing elements that need to be replaced are color coded, for example, white represents an operator and yellow an operand or argument. The insertion point can be placed only between elements and the Group and Undo buttons are enabled. When the Safety Net is off, you can still select elements from the Paste list but can also type directly into the expression box, the 'Group' and 'Undo' buttons are disabled and you can use the Clipboard to cut, copy and paste text into the expression. The Group button allows grouping elements in parentheses.

When the expression is completed, clicking the Ok button will insert the expression into the window or dialog box from which the Expression Builder was opened.

Information about functions is maintained in a table called DBASEWIN.FNF. This is where dBASE for Windows gets the information that is displayed in the Expression Builder. Since dBASE for Windows allows you to write your own functions, these functions can be added to the Paste list by adding the appropriate information to the DBASEWIN.FNF table.

Printing: A basic level of printing capability is available directly from the dBASE for Windows' user interface. This feature is for 'quick-and-dirty' prints of structure or table information. The print speedbar button and menu selection are not available from the Command Window, Catalog Window or Navigator. dBASE for Windows uses the Windows drivers to send output to the printer, selecting File|Printer Setup opens the Windows Print Setup dialog box. Pages are printed with a header that gives the current filename and a footer that prints the page number; these features cannot be changed.

Printing from the Table Records or Query Results Windows will format the printout the same way it appears on the screen, the Browse layout may require more than one page width to fit all the fields in the printed view and it may be advantageous to select the landscape orientation if that option is available for your printer.

Printing from the Table Design mode prints the table structure, from the Query Design mode prints the contents of the QBE file. From the Form Designer, the output shows the objects in the form and their contents. The text editor can be used to print any text file including programs (PRG) and form (WFM) files.

Text Editors: dBASE for Windows includes a Program Editor for creating and editing program files and a Text Editor for working with other text files and memo fields. These are actually the same editor but with different default settings. In terms of cursor movement and editing features the editor looks about the same as any other Windows based editor or word processor.

The Program Editor can be accessed through the Catalog Window, Command Window, Navigator or menu. Programs can be written in any editor or word processor that has the ability to save ASCII text. Because the editor is an integral part of dBASE for Windows, however, it offers the advantages of having access to the Expression Builder as well as being able to run the program directly from the editor so that you can test and debug your code as you write it. If your programming style is anything like mine, this is a crucial feature.

The Program Editor's default settings include Auto Indent and Auto Colors both turned on. If you have used editors incorporated into certain other Borland products, you are familiar with these features. Auto Indent allows automatic alignment of indented lines. Pressing the Tab key at the beginning of a line inserts space characters (ASCII 32), when you press Enter at the end of the line the new line automatically indents to the same level. After any character other than tab or space has been typed on the line, the Tab key insert a true tab character (ASCII 9) to facilitate aligning comments to the same column position. Auto Colors is a feature that color codes syntax elements to ease debugging using the following color scheme:

    • Comments are gray
    • literals are blue
    • non-terminated delimited literals are red
For example, the statement:
"This is a statement.
would appear in red until the closing quotation mark is typed, then it would turn blue.

The Text Editor default settings are Word Wrap off, Auto Indent off, Auto Colors off. When used to edit a memo field, Word Wrap is on and the Right Margin is set to 0 resulting in the text automatically wrapping to the current width of the editor window.

The first two installments of this review discussed the creation of objects from dBASE for Windows' various visual design modes. I did not say much more than that about objects because I felt it would be more appropriate to wait until later. Well, now its later.

Object Oriented Programming

I have been programming for almost ten years in a variety of languages; primarily xBase, Basic and Turbo C, as well as a scattering of such weird languages as Cobol, Fortran and RPG. All procedure based languages. I guess maybe I was a little too heavily ingrained in procedural languages because I was having trouble grasping the concept of object oriented programming. All of the books available seemed to have been written in Martian. That is, until I read the programming documentation of dBASE for Windows. The package includes a card to send for a free book dBASE for Windows, Object Oriented Primer by Michael R Irwin. This is the first explanation of object orientation that I have found that was written in a manner that an old procedure-headed programmer like myself could make some sense of. The book is actually an excerpt from a book called Programming dBASE for Windows and includes a special discount offer card to purchase the book for $28 (it seems the concept of shareware is catching on). Actually, by the time you read this, the discount offer will have expired. [Late breaking update: My check was returned by Random House with a note saying that the book had been canceled and will not be available.]

The first question one must ask oneself when making the transition to object oriented programming is: Why?

The goal of the object oriented design is to manage complexity. It is best suited to projects that are:

    1. frequently modified. As a general rule, object oriented code is easier to maintain and modify.

    2. large and complex. You can model applications after the real world by associating code with a specific object's behavior.

    3. developed by multiple programmers. Variables and subroutines can be hidden inside the object, making it easier to share code with other programmers.

Another important feature of object oriented programming is that it allows for event driven applications. This concept is the most frightening to classical procedural programmers. Simply put, it means that the user, not the program is in control of the sequence of events. In the traditional DOS environment, the user may appear to have a certain amount of control, as when making a menu selection, for example. However, once the selection is made, the program goes its merry way. And everywhere the program went the user was sure to go.

An event driven environment, such as Windows, allows all kinds of strange and magical things to happen. For example, the same document can be opened twice or the same program can be running two different documents. It is also possible for dBASE for Windows to be running a table update, WordPerfect running a spell check and Excel running a stock portfolio analysis all at the same time. The user can freely jump from one application to another or ignore them all and play a game of Solitaire simply by clicking the mouse on an icon or button. The program has to be able to deal with this regardless of external environment settings. The same concept that allows the object to hide its data and procedures from the outside world can also allow it to bury its head in the sand and ignore the world around it.

Objects and Classes

Objects: An object can be thought of as being nothing more than a block of memory that contains a collection of variables. Some of these variables will contain data and others will hold pointers to functions. An object can also contain other objects. A good example of this is the Form. Last month I talked about creating forms from the Form Designer and placing various controls (Entryboxes, Pushbuttons, etc.) in the form. Each of these controls is a separate object.

The variables within an object are its properties (discussed briefly last month). A property that has code associated with it (i.e. a function pointer) becomes a method. An event is a method that is activated by an action. Events can be triggered by the user, by dBASE or another Windows program or by Windows itself.

When you create an object you are creating an instance of a class. This process is known as instantiation.

Classes: A class is a template or skeleton used for the creation of multiple identical copies of an object. This way, you do not have to rewrite the code each time an object is created. A class can also be used to create a new class by changing the value of properties and/or adding new properties. The new class will automatically have all of the properties of the original class. This feature of classes is called inheritance and is one of the reasons that object oriented code is easier to modify.

An object can be thought of as being analogous to a memory variable. Using this same analogy, the class would be similar to a data type. When you create a numeric variable, the numeric data type specifies what kind of data can be entered into it and what operations can be performed with it. When you create a form object, the form class specifies the rules that determine how that object can be manipulated.

xBase extensions

Several of the commands and features of dBASE for Windows' programming language are solely for the purpose of maintaining compatibility with earlier versions. For this reason, programs written in dBASE III+ and dBASE IV can be run from dBASE for Windows usually with no modification.

In the February PC Alamode, when I wrote chapter (volume?) 1 of this book, the section on tables included a discussion of several new data types. Now that the topic has turned to programming, two additional new data types (lightly brushed over last month) are available to group and execute commands:

    • Codeblock is a new data type that stores small, unnamed groups of expressions and commands.

    • Function Pointer is a data type that stores references to functions, procedures and codeblocks.

As data types, codeblocks and function pointers can be assigned to variables or object properties or passed as parameters. All event properties of dBASE for Windows' built-in classes accept the codeblock and function pointer types.

Procedures and functions: In the past, the distinction between procedures and functions has been fairly clear. A procedure is a subroutine. A function is a subroutine that must return a value. With dBASE for Windows, however, it is now possible for a procedure to optionally return a value. Therefore, the only real difference is in the eye of the programmer. That is, if it does not return a value, it is a procedure; if it does, it is whatever you want to call it.

Multiple syntax: To accommodate programmers with a variety of backgrounds, dBASE for Windows recognizes several syntax conventions. For example, to create a form called MyForm with the title this is my form, add a new property called MyNumber and a pushbutton that closes the form, you could use the DEFINE syntax that will be familiar to dBASE IV programmers:

    DEFINE form MyForm from 5, 5 to 15, 60 ;
	property text 'this is my form',;
	custom MyNumber 3
    DEFINE pushbutton MyButton of MyForm at 2,2 ;
	property ;
	    text 'close',;
	    OnClick {; MyForm.close()}
    open form MyForm

On the other hand, programmers experienced in object oriented languages such as C++ or Pascal will be more familiar with the following syntax using the NEW operator.
	MyForm = NEW FORM()
	MyForm.top = 5
	MyForm.left = 5
	MyForm.height = 11
	MyForm.width = 56
	MyForm.text = 'this is my form'
	MyForm.MyNumber = 3

	MyButton = NEW Pushbutton(MyForm)
	this.text = 'close'
	this.OnClick = {; form.close()}

	MyForm.open()
Both of these examples instantiate and open the exact same form object. The styles can be mixed and intermingled to create your own style.

These examples also illustrate a few other significant points.

    1. The line OnClick {; MyForm.close()} is an example of assigning a function pointer to a property (in this case, an event). The close() function is part of dBASE for Windows' built-in form class.

    2. Notice the use of the dot operator (.) to reference properties of the object. Most programmers will be familiar with this notation used to reference members of a type in Basic or a structure in C; its all the same difference.

    3. This and Form. The keyword this refers to the current object; form references the form object that contains the current object. These features, although trivial in the example above, are what give objects their power. When the program is compiled, the compiler will substitute the appropriate name. Now, if I want to use the button in a different form, clicking the button will close the form regardless if it is called MyForm, DataEntry or UncleGeorge. No reprogramming is required.

Conclusion

When Borland acquired Ashton Tate, the database community said 'Wow, we're finally going to get a version of dBASE for Windows.' So we waited, and waited. In fact, Borland has been showing prototypes for over 3 years. Now finally the wait is over, and the reason it took so long is obvious. dBASE for Windows is a robust, powerful and fully object oriented RDBMS. It could have been released earlier without all the bells and whistles but Borland was wise to wait until it was 'finished'. Several major software companies have been hurt recently by releasing new products too early, in fact accusations have been made of releasing betas.

Although making the move to a Windows-based DBMS can take some getting used to and some of the features may work differently then the experienced dBASE DOS user might expect, I think dBASE for Windows was worth waiting for and is a worthwhile investment for the serious database user.

Part 1
Part 2
Part 3