RBA
RBA

Reputation: 12584

Delphi - what event is triggered inside TDBGrid on dataset.enablecontrols

I need to know what happens in a TDBGrid when the dataset is calling enablecontrols. I understood that dataset is notifying the datasource, but I don't know what is called on the dbgrid component before the OnDrawCell event.

from db.pas the dataset is calling

  if (FDisableState <> dsInactive) and (FState <> dsInactive) then
    DataEvent(FEnableEvent, 0);

How the datasource is notifying the dbgrid about how many columns it needs to display?

Upvotes: 1

Views: 1805

Answers (1)

NGLN
NGLN

Reputation: 43649

DataSources are linked to data-aware controls via data links (TDataLink). Every data control creates a DataLink in order to respond to and to signal the attached DataSource.

The DataLink of a DBGrid is of type TGridDataLink which is created in TCustomDBGrid.CreateDataLink.

This is the call stack after TDataSet.EnableControls:

  • TDataSet.EnableControls calls TDataSet.DataEvent,
  • TDataSet.DataEvent calls FDataSources[I]).DataEvent for all attached data sources,
  • TDataSource.DataEvent calls TDataSource.NotifyDataLinks, which calls TDataSource.NotifyLinkTypes,
  • TDataSource.NotifyLinkTypes calls FDataLinks[I]).DataEvent for all attached data links,
  • TDataLink.DataEvent calls TGridDataLink.DataSetChanged or TGridDataLink.LayoutChanged, depending on what happened before EnableControls was called. An edit to a record is a dataset change; an addition of a field (column in the grid) is a layout change (among others),
  • TGridDataLink calls FGrid.DataChanged or FGrid.LayoutChanged,
  • TCustomDBGrid.LayoutChanged eventually calls TCustomDBGrid.BeginLayout,
  • TCustomDBGrid.BeginLayout delegates the update of the columns (count, titles, etc.) to the Columns property and calls Columns.BeginUpdate.

OnDrawCell takes place sometime in the future, when all layout changes are made.

Upvotes: 4

Related Questions