[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] | Reference for unit 'DB' (#fcl)

# TDataSource

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

Component representing the link between a local (GUI) component and a dataset

## Declaration

Source position: db.pas line 1900

`type TDataSource = class(TComponent)`
`public`
`constructor Create(); override;` |  | Create a new instance of TDatasource
`destructor Destroy; override;` |  | Remove a TDatasource instance from memory
`procedure Edit;` |  | Put the dataset in edit mode, if needed
`function IsLinkedTo();` |  | Check if a dataset is linked to a certain dataset
`property State: TDataSetState; [r]` |  | State of the dataset
`published`
`property AutoEdit: Boolean; [rw]` |  | Should the dataset be put in edit mode automatically
`property DataSet: TDataSet; [rw]` |  | Dataset this datasource is connected to
`property Enabled: Boolean; [rw]` |  | Enable or disable sending of events
`property OnStateChange: TNotifyEvent; [rw]` |  | Called whenever the state of the dataset changes
`property OnDataChange: TDataChangeEvent; [rw]` |  | Called whenever data changes in the current record
`property OnUpdateData: TNotifyEvent; [rw]` |  | Called whenever the data in the dataset must be updated
`end;`

## Inheritance

`TDataSource` |  | Component representing the link between a local (GUI) component and a dataset
`TComponent,IUnknown,IInterfaceComponentReference`
`TPersistent,IFPObserved`
`TObject`

## Description

TDatasource is a mediating component: it handles communication between any DB-Aware component (often edit controls on a form) and a TDataset instance. Any database aware component should never communicate with a dataset directly. Instead, it should communicate with a TDatasource instance. The TDataset instance will communicate with the TDatasource instance, which will notify every component attached to it. Vice versa, any component that wishes to make changes to the dataset, will notify the TDatasource instance, which will then (if needed) notify the TDataset instance. The datasource can be disabled, in which case all communication between the dataset and the DB-AWare components is suspended until the datasource is again enabled.

## See also

TDataset |  | Base class for records-based data-access
TDatalink |  | Data event handling agent for controls