Previous Topic

Next Topic

Inhoudsopgave

Book Index

TDataSource Component

TDataSource

Description

Provides an interface between a dataset component and data-aware controls on a form.

Remarks

Use TDataSource to provide a conduit between a dataset and data-aware controls on a form that enable display, navigation, and editing of the data underlying the dataset. All datasets must be associated with a data source component if their data is to be displayed and manipulated in data-aware controls. Similarly, each data-aware control needs to be associated with a data source component in order for the control to receive and manipulate data.

TDataSource Properties

Property Property AutoEdit: Boolean (R/W)

Determines if a data source component automatically calls a dataset's Edit method when a data-aware control associated with the data source receives focus.

Property Property DataSet: TDataSet (R/W)

Specifies the dataset for which the data source component serves as a conduit to data-aware controls or other datasets. Set DataSet to the name of an existing dataset component either at design time, or at runtime. By changing the value of DataSet at runtime an application can effectively use the same data-aware controls to display and edit data in different datasets.

Property Property Enabled: Boolean (R/W)

Determines if the data-aware controls associated with the data source component display data. Use Enabled to control whether data-aware controls connected to a data source display data. If Enabled is true (the default), data are displayed. If Enabled is false, all controls associated with the data source are blank.

TDataSource Events

Event Event OnDataChange

Occurs when the data in a record has changed, either due to field edits or moving the cursor to a new record. Write an OnDataChange event handler to take specific actions when a field in the current record has been edited and the application moves to another field, or when the current record in the associated dataset changes. OnDataChange is especially useful in applications that must synchronize data display in controls that are not data-aware. This event is typically used to make sure the control reflects the current field values in the dataset, because it is triggered by all changes. Methods that can trigger this event include the Next or Prior methods for the dataset. Data-aware controls notify a data source of a data change when:

Event Event OnStateChange

Occurs when the state of a data source component's dataset changes. Write an OnStateChange event handler to take specific actions when the State property changes for a dataset associated with a data source component. During the course of a normal connection to a database, a dataset's state changes frequently. For example, each time a user starts editing a field in a data-aware control the dataset's State property is changed from dsBrowse to dsEdit if the State is not already dsEdit. An OnStateChange event handler can respond to changes in state by taking actions such as disabling or enabling menu items or buttons.

General Data-Aware Control Properties

Property Property DataField: String (R/W)

Property Property DataSource: TDataSource (R/W)

Property Property ReadOnly: Boolean (R/W)