PrevNext
EhLib
User's guide

 Using TDBSumList component

Common understanding of TDBSumList.

You can use TDBSumList for totaling records in a TDataSet with visible dynamic changes. Set the DataSet field in the dataset for which you want a watch, and write an SumListChanged event to take specific action after TDBSumList has changed. TDBSumList have SumCollection property that represents a container of TDBSum objects. Every TDBSum object represents a element that can hold specific aggregation value. FieldName and GroupOperation determine type of aggregation value, SumValue hold current aggregation value.

TDBSumList is imbedded in DBGridEh component, so all below text in equal degrees pertains as to TDBSumList component as to TDBGridEh.SumList property.

How it work and why SumList sometimes calculate aggregation values incorrectly.

As you know data-aware controls interact with dataset via TDataLink object. TDataLink does not allow to recalculate aggregation value quickly. For instance when the record is deleted from dataset, dataset sends to all TDataLink objects deDataSetChange event, same event is sent when the local filter have been changed. So when TDataLink receive such event it have to recalculate aggregation value running through whole dataset, even when only one record have been deleted from dataset. After activations, TDBSumList overloads following events of the dataset: OnAfterEdit, OnAfterInsert, OnAfterOpen, OnAfterPost, OnAfterScroll, OnBeforeDelete, OnAfterClose. This way allows to avoid of running through whole dataset when it is not need but other problems is appear such as:
    Assigning these events at runtime. Deactivate SumList Before assignment to one of the aforesaid events.
    Under some conditions SumList can raise exception of access violation. SumList try to return events to dataset but dataset have been deleted. Such situation can appear when SumList (or grid) and dataset placed in different forms (datamodules). In such situation try to deactivate SumList before form or datamodule with dataset will be deleted.
    SumList can not trace changes in dataset if you use SetRange or ApplyRange methods. Call SumList.RecalAll after using such methods.
    SumList can not trace changes in master dataset for detail dataset for not BDE datasets. Call SumList.RecalAll after changing active record in master dataset.
In any other cases if you see that under some conditions SumList calculate values incorrectly then call RecalAll method.


EhLib Team
E-mail: support@ehlib.com