Step Two Open a database object

This step will connect to a database. The BDE accesses all tables through the context of a database. Single-tier applications will generally create an alias to a file system directory and utilize that as the database context. The function DbiOpenDatabase is used to open a database dbiREAOWRITE, dbiOPENSHAREO, nil, 0, nil, nil, hOB This sample function call opens the DBDEMOS database, assuming that it has been properly configured within the BDE. The second parameter, STANDARD in this case,...

The DataSource Component TDataSource

The DataSource component is the pipeline between a dataset and the data-aware components. This intermediary component is required any time that data-aware components and dataset components are to be utilized on a form. The DataSource component requires a matching DataSet component in every case. The DataSource control also enables the linking of datasets in master-detail parent-child relationships. The DataSource component surfaces a limited number of published properties for use at design or...

Data Access functions

These functions perform data access operations on tables.

Environmental Functions

The BDE environment functions return information pertaining to the application environment. This includes the supported table, field, and index types or available types. In addition, tasks such as loading a specific driver or initializing the engine fall into this category. DbiDeleteAlias DbiDeleteDriver DbiDllExit DbiExit

Database Explorer Interface

The appearance of the Explorer closely matches the format seen in the BDE Administrator. Figure 4.16 shows the dual-paned window used for all actions in the Explorer. The left pane contains two tabs the Databases tab listing all database aliases defined to the BDE and the Dictionary tab showing the contents of the data dictionaries that have been defined. ffi- CflSS CRSYB -jS dBASE Fies DBBOEMOS S Tables ffi- CflSS CRSYB -jS dBASE Fies DBBOEMOS S Tables SHU neighbor.dbl -H REGISTER.db 0 Fields...

Form Reports

Form reports use more of a free-form layout when presenting data to the user. Rather than list the data rows, the data is presented in different areas of the page for clarity and readability purposes. A good example-krf this type of report is an invoice. The top of an invoice will usually cor the customer's name and address, contact, and telephone information. Below that, the invoiced items are listed and summarized, usually ending with an amount owed. The next project creates a form report...

Local SQL

There are a number of items that are specific to Local SQL that should be mentioned prior to discussing the statement syntax. The sections that follow highlight the syntax rules that are specific to the formulation of the SQL statements using the Local SQL implementation. When developing in a multi-tier environment, refer to the other product documentation to determine its specific requirements. Local SQL is enhanced to handle multiple-word table names. Table names can include the full path and...

Alternatives to the Borland Database Engine

Among the advantages of the separation of the BDE from the internals of Borland's development products is the freedom of choice. The open architecture of the Delphi development environment allows you to replace the database engine with other, sometimes better, products, Why would you want to consider this avenue The reason that is most often listed supporting the replacement of the BDE is size and overhead. When you create a Delphi application and prepare it for distribution, you must also...

Packing Paradox Tables

Paradox tables do not need to be packed as often as dBASE tables. When a record is deleted from a Paradox table, that space is made immediately available to new entries. The situation may arise where a large number of records are deleted all at once, leaving a lot of unused space in the table that will not be immediately filled. To pack Paradox tables you are required to use a different function, DbiDoRestructure. Working with Paradox tables requires that you use a structure called CRTblDesc, a...

Database Functions

The BDE functions listed here perform database-level tasks information about a database as a whole.

The DBImage Component

It's a graphical world out there, and Delphi's darabase supporr for a graphics object is second to none. Nearly all database products sup ported by the BDE support the inclusion of bitmapped graphics in BLOB Binary Large OBject data fields within the table. BLOBs are not Chapter B-Delphi's Data-Aware Components limited to being containers for graphics but this is one of their most common uses. If a field type is supported by the BDE you can count ofl Delphi offering a component to work with...

The BorlanduDaiabase Enmne an the Database UtteT I

he Borland Database Engine BDE is the motor that drives all of the database functionality in Delphi as well as C Builder, Visual dBASE, and Corel's Paradox. Originally brought to life as IDAPI Independent Database Application Programming Interface , an open database connectivity product, its popularity in this context has been usurped in recent years by ODBC. Borland's decision to focus the engine back on its core tasks has been very beneficial to the BDE and developers who utilize it. The...

DbiAnsiToNative LdObj NativeStr AnsiStr Len bDataLoss

Pointer to the language driver object returned from calling DbiGetLdObj. The translations string. The client buffer containing ANSI data. Specifies the length of the buffer to convert. If 0, a null-terminated string is assumed. If the result is True. the ANSI string cannot map to a character in the native character set. Appendix A BDE API Quick Reference DbiAnsiToNative functions as a translator of strings from ANSI to the language driver's native character set. DbiAppendRecord hCursor,...

The Table Component TTable

The Table component is generally the first data access control that you will pair with a DataSource control to construct a database application. It has been designed to provide uniform access and navigability to each row in the table types supported by the BDE regardless of the underlying rules of the dataset source. Despite the wide range of properties, it can be quite simple to use. Place a table component on a form, set the Database and Table properties to point to the relation you want to...

HideSelection

The DBRichEdit component allows selection of blocks of text either with the mouse or through standard Windows keyboard methods and_ marks the text in the standard fashion with a colored block highlight it. Depending on the setting in the HideSelection property this selection-marking may remain or disappear when the focus shifts to another control. Setting this property to True will cause the selection marking to be visible only when the focus remains on this component. When the visual cue of...

Index Functions

These functions create or drop indexes or return information about a specified index. DbiAddlndex DbiCloselndex DbiCompareKeys DbiDeletelndex DbiExtractKey DbiGetlndexDesc DbiGetlndexDescs DbiGetlndexForField DbiGetlndexSeqNo DbiGetlndexTypeDesc DbiOpenlndex DbiRegenlndex DbiRegenlndexes DbiSwitchToIndex The BDE functions listed acquire or release record or table locks or return information about a lock's status. Part Ill-The Well-Rounded Application

Step Eight Position the record point on the appropriate record

This step introduces some new vernacular to the developer's vocabulary in the use of the word crack. Cracks are the imaginary lines that separate each record in a database. Using this terminology allows you to envision the record pointer being positioned before the first record in a table or after the last. You can also place it between two records, committed to neither. Use the DbiSetToBegin function to set the pointer to the crack before the first record 282 Part III The Well-Rounded...

Key Properties 4

The properties that will receive our attention here are those that are unique requirements of the image orientation of the control. The value of this property determines whether or not the contents of the graphic BLOB will be automatically displayed. When set to True, each time the contents of the BLOB field change, such as when the user browses from row to row in a dataset, it is automatically redrawn. Depending on the size of the image, this continual redisplay of the graphics could become a...

CrossTab Reports

The last type of report that we are going to create is a cross-tab report. This style of report is an analytical tool that summarizes on different planes the numbers that intersect. Placing this process in context requires that we set the scene with a typical report of sales information. The first application that we are going to produce uses a Query component instead of the Table controls that we have used as the source, The information will be in the form of a grouped report in which the...

Key Pr operties

The lookup controls take a little study to integrate properly into your application, and the key to understanding them is to be knowledgeable about the settings for the properties. The KeyField property identifies the field from the source listed in the ListS ource property that must match the value of the field specified in DataField. This links the ListSource dataset to the DataSource. The fields do not need to share a name but must have the same values. The field specified in KeyField is not...

The Database Component TDatabase

Every Delphi database connection is encapsulated by a Database corn-ponent, whether or not you actually place one in your project. The Database component is responsible for providing all of the connection information from the database to your application. An automatically generated database component is instantiated for each BDE application- to encapsulate the connection. The most important task of the Database component is to provide your application with information about the type and...

Creating the Table at Design Time

One word of warning before approaching this task You must be well versed in the TTable class before putting this information to work in a production situation. You are going to be defining every aspect of a Table without the benefit of the Desktop, which masks a lot of this from you and automates many operations. The properties, methods, and events of the Dataset object should be reviewed to ensure that all of the values that you are going to define are appropriate for the object that you want...

Along Came Codd

In 1968, while working as a researcher for IBM, Dr. E.E Codd began to examine the possibility of applying the uniformity and consistency of mathematics to the undisciplined field of database management. His research resulted in the now-classic paper, 'A Relational Model of Data for Large Shared Data Banks, which was published in 1970 and Chapter I Introduction to the Relational Database H 9 This first property is of primary importance, as it sets the stage for many of the later properties and...

Entries in Each Column are from the Same Domain

A domain is the defined set of values from which the data in a column can be drawn. This pool of values describes the entire range of acceptable data elements. For example, the domain of the column Employee-ID is the range of valid employee ID numbers. Items not belonging to that collection of values, such as the employee's last name or an ID number beyond or below the valid range, fall outside of the domain for that column. With a domain for each column defined, the user is rewarded with...

Addressing the SQL String List Directly

After seeing the two alternative methods for adding the SQL sratements to the Query component's SQL property, this section might seem a bit anticlimactic. There is no great mystery to loading the property using the Add method. The code block below shows that the process is straightforward with Query 1 do begin Close SQL.Clear This simplified method lends itself well to taking a building block approach to the construction of the SQL sentence. To show what this means, consider the same statement...

The DBChart Component

The DBChart control is another of Delphi's hidden gems that is available to lend additional features to your application. The class is derived from the TChart class and is extended to utilize a dataset for the source of its data series. Using the columns of a dataset for its source, the chart becomes a dynamic display that is updated as the dataset is modified. You have a wide variety of chart type options to choose from and all of the parameters of the display can be controlled within an...

Entity Integrity

The first rule is simply a repeat of the earlier structure requirement that each row in a table be unique. The entity integrity rule requires that no part of the primary key of a table be allowed to accept null values. Blank data fields do not lend themselves to an adequate description of the row, so requiring data elements in the column or columns that make up the key to the row makes perfect sense. Requiring that the key for each row be unique fulfills the mission of the relational model....

OnResizeRequest

This event fires when the edit control attempts to resize to accommodate expanding or contracting text. The application then has the opportunity to adjust or retain the edit window size and manipulate-necessary user interface elements to handle the text. The OnSaveClipboard event is fired when Windows is in the middle of transferring data to the clipboard and the user is attempting to destroy the edit window that is the source of the data. The event handler can be written to delay the window...

Configuring a Standard Database

A standard database, which includes the Paradox, dBASE, ASCII, or FoxPro drivers, will expose a small set of configurable options. Exploring the standard database configuration options is best performed by creating a new object. To add a new alias 1. Click on Object New from the menu or right-click on the Databases tab and select New. 2. The New Database Alias dialog will be displayed from which the database driver is selected. This option determines the type of alias that will be created....

DbiExit

Part III The We I-Rounded Application Part III The We I-Rounded Application DbiExit disconnects the application from BDE. It releases all resources allocated by the client application and should be the last DBI BDE call made by the client application. DbiExtractKey hCursor, pRecBuf, pKeyBuf Pointer to the record buffer that contains the key to be extracted. The variable to receive the key value. The function DbiExtractKey gets the key value for the current record from either the cursor or the...

DbiCloseDatabase hDb

closes the specified database and any associated The function DbiCloseFieldXlt closes a field translation object. DbiCloselndex hCursor, szlndexName, ilndexld The cursor handle. A pointer to the index name. Currently not used. The function DbiCloselndex closes the specified index for the cursor. DbiCloseSession closes the session and frees all resources associated with it including database handles, cursor, table-level locks, and record-level locks. DbiCompareBookMarks hCur, pBookMark I,...

DBNavigator Events

Two events are native to the DBNavigator class, both allowing you to trap the push of one of its buttons and initiate any special processing that you want to implement. The BeforeAction fires when a button on the navigator is clicked but immediately before the default action for that particular button is executed. is fired when any type of click event occurs. This includes a mouse click, the spacebar being pressed when the navigator has focus, or the Btn Click method being called. The default...

Cursor Functions

These functions either perform an action on a cursor, such as positioning, linking, or creating and closing a cursor, or return information about a cursor. DbiApplyDelayedUpdates DbiBeginDelayedUpdates DbiBeginLinkMode DbiCloneCursor 294 Part Ili-The Well-Rounded Application

Alphabetic Function Listing

DbiAcqPersistTableLock hDb, szTableName, szDriverType Reference to the table's driver type. DbiAcqPersistTableLock acquires an exclusive, persistent table lock that prevents other users from accessing the table or creating one of the same name. DbiAcqTableLock hCursor, eLockType Specifies the type of table lock required. DbiAcqTableLock allows the user to acquire a table-level lock that can prevent other users from updating a table. DbiActivateFilter hCursor, hFilter The handle to the filter to...

Session Functions

These functions return information about a session or perform session-related tasks. Chapter 9-The Borland Database Engine API This list of functions performs tasks related to the tables. Some will return information about a table such as lock status, a list of referential integrity links, or the indexes open on the table. Functions that perfon 0 table-wide tasks such as copying and deleting are also included. DbiCopyTable DbiCreatelnMemTable DbiCreateTable DbiCreateTempTable DbiDeleteTable...

The DBRadioGroup Component

The DBRadioGroup component is a data-aware version of the RadioGroup control. Similar to the data-aware list components, it presents the user with a limited choice of selections for a data field. The user selects the value that they want to enter for the field by select ing one of a group of radio buttons. A radio button interface should only be used in situations where the number of choices is very limited. The mutually exclusive nature and default selection options of these controls require...

First Normiai Form INF

To be in first normal form, a relation must have no repeating groups or multi-valued attributes. The class and grade fields in Figure 2.10 area good example of a non-relational design. Each student record maintains the names of up to four classes and grades. To be a relational table, each attribute, or field, must represent a unique, discrete fact about the entity. The fields in the example relations represent duplication of the data. It is a simple matter to reduce this relation to first...

Key Properties 6

The properties of the DBListBox are mainly composed of the commonly inherited set of values. There is a common pair of properties, however, that often is misunderstood in the context of this control. The DataSource and DataField properties do not refer to a field that supplies the items for the item list, but instead the DataField property determines the receiver for a choice from the list of strings. The string list is defined at design time or modified from some other external source at run...

The DBLookupListBox and DBLookupComboBox Components

This pair of components is so similar in nature that it makes sense to discuss them in tandem. DBLookupListBox and DBLookupComboBox are data-aware controls that build their display items lists from either of two sources The data can come from a lookup field defined in a dataset or from a secondary data source altogether. The controls present the user with a limited list of choices with which to fill the associated dataset field. Physically, these controls are the same as their non-lookup...

The DBRichEdit Component

The DBRichEdit component is a data-aware control that can display formatted text stored in BLOB fields. Rich Text describes text fields that support the formatting of individual characters, words, and paragraphs. Text searching and printing functions are supported by Rich Text controls and by default they support the following types of formatting Font attributes such as typeface, size, color, etc. Text alignment, tabs, indentation, and list numbering The conversion of Rich Text to plain text...

The Query Component TQuery

The Query component is similar in nature to the Table component it provides a method of accessing table data from a wide variety of sources and making it available to the application. What makes it different from the table is that it uses SQL SELECT statements to build the dataset that it displays. The property list for the Query component is detailed in Figure 5.4 and as you will notice, it looks remarkably similar to the property set of the Table. This, of course, is because both the Table...

The DBMemo Component

The DBMemo component is the brother to the DBImage data-aware control it displays BLOB data from the associated database field. The BLOB data supported by this control is large blocks of text in Memo fields. Memo data is free-form text in which the user has the benefit of a variable length field. With no constraint placed on the maximum size of the field, the user is able to maintain lengthy collections of text, updating it as necessary. The text contained in the field can be subject to a...

TDataSource Events

There are three event handlers exposed by the TDataSource class Each of the event handlers fires on a change in the dataset to which it is connected. It does not reflect any change in the DataSource the control remains a simple intermediary The OnDataChange event is triggered by the cursor moving to the next or previous record any method that results in a change in the cursor position will trigger this event. This event is especially useful for ma' ally synchronizing components. Whenever the...

OnColEnter

The OnColEnter event fires when the focus shifts into a new cell in the grid including navigation by keyboard or mouse click. OnColExit events fire when the focus is in the process of leaving the cell. This event fires when dragging with the mouse moves a column. OnColumnMoved occurs just after the column has been moved. This event is provided to give the application an opportunity to repaint a cell. The OnEditButtonClick event fires when the ellipses button on a drop-down or pick list column...