Summary

The discussion in this chapter provided a survey of the functionality of the core of Delphi's database access, the Borland Database Engine. The driver-based architecture of the BDE makes it, and your applications that utilize it, infinitely extensible. This design allows the BDE to support your application needs from the desktop all the way to complex multi-tier applications supporting a wide variety of SQL databases. The ODBC socket extends the BDE support to cover nearly every desktop and midrange database currently on the market. The transparency of the engine and the low-level requirements of each database type allow the Delphi developer to concentrate on interface and functionality issues rather than the database access components of a project.

The Borland Database Engine is not a single executable file but rather an entire suite of executables, drivers, and utilities. We have covered the majority of the engine level functionality in this chapter. If your application needs focus on an individual file type, it is recommended that you explore further the unique capabilities of that database through the engine documentation.

Looking Forward

The next chapters will finally get into the meat and potatoes of Delphi database programming. The data access components will be examined first since they are the ones that actually link the program to the data files. Then the data controls are put to work, creating the outstanding interface that Delphi is famous for.

  • The Dataset Objects ■ The Table Component (TTable)
  • The Query Component (TQuery) ■ The Datasource Component (TDataSource) I Putting the DataSource, Table, and Query Components to Work ■ The Stored Procedure Component (TStoredProc) ■ The Database Component (TDatabase) ■ The Session Component (TSession) ■ The BatchMove Component (TBatchMove)
  • The UpdateSQL Component (TUpdateSQL) ■ The NestedTable Component (TNestedTable)

in ally, we arrive at the Delphi promise of RDAD, Rapid Database Application Development. Dash out a form, slap some components on that surface, point the components towards your database, and voilà— a database application is born. Building database applications in Delphi can be that easy but only after spending the requisite time exploring the power of the tools. Like everything else in Delphi, the database components are rich with functionality and adaptability, and the effort: expended to build your knowledge on these classes will result in greater user satisfaction and measurably higher quality in your applications.

The data access components, available to the Delphi developer from the so-named tab of the component palette, are non-visual components that expose the BDE database capabilities to the Delphi development environment. All database access and manipulation is performed through these components. This chapter wil 1 cover all of these base components, their properties, and events.

106 ■ Part II—The Delphi Database Tools

The Dataset Objects

A dataset is the base building block of any database application. These are the objects that contain or access the data; the facts that we are % attempting to manage. The most immediately familiar dataset object the table, a structure that we have discussed at length in the precei pages. There are four components on the data access palette that are derived from the TDataSet base class: Table, Query, Stored Procedure, and NestedTable. Before examining the individual classes, the unde1 ing class from which they inherit the majority of their functiona lity be laid open.

The DataSet Object (TDataSet)

The TDataSet object (Latin name, TDataSet) is the core unit that enables access to tables through the BDE or other database access points. A TDataSet object is the ancestor class from which all other dataset objects are derived and models such real-life items as a tl a database or a query that presents a subset of this data. The das defines a set of fields, properties, methods, and events that are ini! ited by all of the descendants. You cannot utilize the TDataSet oh ij directly because many of the properties and methods are virtual or abstract. A virtual method is one that is defined in the base class but can be overridden in descendant classes. An abstract method in a base class provides a function prototype but no implementation; descendants are required to provide the implementation. This object model is perfect for implementing these database components: Each is built for the cask of accessing data; they just use different methods of accomplishing the job.

There are three classes that are direct descendants from TDataSet. TBDEDataSet enables the TDataSet class to work with the BDE to enable database access (TDataSet itself is database engine indepen d* ent). The TDBDataSet component is a descendant of the BDE-enai TDataSet that adds additional session and database features. If you -were to develop your own data access components, you would most" likely create a descendant from the TDBDataSet class. The last clas also a direct descendant of TDataSet, TClientDataSet. This class is designed to implement multi-tier database applications using di uted databases.

Chapter 5—Data Access with Delphi pataSet States

Before we talk about what can be done with a dataset, it is important to understand under what condition we are addressing the table The state of the dataset is a read-only flag that determines what actions Ciii and cannot occur at any specific moment. The table in Figure 5.1 summarizes, the. passible states that are communicated by the tables.

dslnactive dsBrowse

DsEdit

Dslnsert

DsSetKey

DsCalcFields

DsFilter

Inactive

Browse

Edit insert

SetKey

CalcFields

Filter

Description

This state indicates that the data in the tabid not available. The dataset is closed..

This is the default state for a dataset; indicates that it is open for viewing but not modification.

This state indicates that the data in the tabid not available. The dataset is closed..

The data in the current row can be modified.

Indicates that a new row is to be inserted or appended.

Range or key value can be set for use in a GotoKey operation or a range (Table or ClientDataSet only).

This state indicates that calculated fields are being processed and prevents changes to

DsCalcFields

CalcFields

Range or key value can be set for use in a GotoKey operation or a range (Table or ClientDataSet only).

This state indicates that calculated fields are being processed and prevents changes to

DsFilter

Filter

This state indicates that a filter operation is occurring. The dataset view is restricted and no change can be made to the data.

Figure 5. I Possible states of a TDataSet descendant

This state indicates that a filter operation is occurring. The dataset view is restricted and no change can be made to the data.

Figure 5. I Possible states of a TDataSet descendant

Each of the state values shown breaks down into one of two basic conditions-the table is either open or closed. A closed dataset object does not expose any of the data contained within to either browsing or modification. In order to perform these operations, the dataset must be opened. Delphi has two methods of performing this function. You can set the Active property of the dataset object to True, either at design time or programmatically at run time:

Vendors. Active := true;

You can also call the Open method at run time:

Vendors. Open;

Many operations, such as setting the current index, also require that the dataset be closed and reopened for the effects to be seen. Delphi provides two methods for performing this task as well. The Active property of the dataset can be set to False at design or run time:

Vendors .Active := False;

or, you can utilize the Close method of the dataset:

Vendors.Close;

When the dataset state falls in the open category, the developer must be aware of two factors: what actions can be performed against the database and how the dataset arrived at the current state. For example, a dataset object linked to a data-aware control can be displaying the data but the user may find that he is unable to edit the current record. The developer should be aware that the default state of a dataset, Browse, will allow browsing of the data values but no modifications. The state of the dataset will have to be changed to Edit before any changes can be applied. Depending on the dataset component used, certain combinations of properties can be set to automatically set the state to Edit upon accessing the table. Awareness of these conditions is important in your design considerations and in testing your application prior to rollout.

Was this article helpful?

0 0

Post a comment