The Data Source Component TData Source

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.

Chapter S—Data Access with Delphi

Chapter S—Data Access with Delphi

Key Properties

The DataSource component surfaces a limited number of published properties for use at design or run time; these are summarized in Figure 5.5. Since the number of published properties is so small, the majority of them are key to extracting,, the best performance from yo0$$ application.

Auto Edit
Figure 5.5 TDataSource component properties

When the value of this property is set to True, the associated dataset automatically enters the Edit state when a connected data-aware control is updated. When it is set to False, the application must explicitly change the state of the dataset to Edit through a call to its Edit method before the user can update the data.

The convenience of defaulting to the Edit state is a good choice for most programs but should be considered carefully for more critical applications. You may want to exercise more control over exactly wher updates can be performed by either having the user explicitly turn on the edit functionality or having the program review the conditions under which the update is being performed.


This property defines the dataset to which the DataSource component; is connecting the interface components. The value of the property is selected either through use of a drop-down list of available dataset components or through manual entry of the name. The DataSet compci nent must be added to the form prior to attempting to enter this val ue attempts to enter a nonexistent dataset name will result in an error message.

This property is the switch that controls the visibility of the data contained in the dataset. When this property value is True, the DataSource is connected to the dataset and any controls that reference the DataSource will display current data. (This is provided that the Table, etc., is in an active state). A value of False will serve to disconnect the _ data-aware controls from the dataset.

The value of the property can be modified at run time in order to temporarily disconnect the controls from the dataset, although this is not recommended. The preferred method of performing this operation is -through the DisableControls method of the dataset.

Tip The component name seems to be the simplest of all of the properties, needing no explanation. Why not take advantage of this property to make your own work easier? Name the component something similar to the name of the component that it is connected to. Grouping controls like this in a complex application will make your life a lot easier.

Was this article helpful?

0 0

Post a comment