Data Cursor
TDataCursor¶
Any TDataItem
can be sorted and filtered without altering its data arrays. TDataCursor
creates a "view" of a data table or column. A "view" is essentially an index (an array of row integer positions).
TBIDataSet
component includes a TDataCursor property to perform these operations, which in turn are used in TBIGrid
and TBIChart
.
A TDataCursor
can also be used when exporting data (to JSON, XML, CSV, Excel, TDataSet, HTML, etc).
The TDataCursor
"Loop" method sorts and filters data and traverses the resulting view, calling a user-defined procedure:
uses BI.DataSource, BI.Arrays; var MyCursor : TDataCursor; MyCursor:= TDataCursor.Create; MyCursor.Data:= Orders; // .... we can set here the SortBy, Filter, etc properties... MyCursor.Loop( procedure( const AIndex: TInteger) begin WriteLn( Orders['ProductID'].DataToString( AIndex ) ); end);
This is equivalent to calculating the cursor "Index" and doing a "for" loop on the index:
var t : Integer; MyCursor.PrepareIndex; for t:=0 to High(MyCursor.Index) do WriteLn( Orders['ProductID'].DataToString( MyCursor.Index[t] ) );