Delphi livebinding TClientDataSet TStringGrid runtime
in Firemonkey (XE5) I created a Frame with a TStringGrid and want to add a "procedure ShowData( aClientSet:TClientSet);" in that pprocedure the rows of the Clientset shall be shown readonly with LiveBindings (TBindSourceDB ?) without knowing anything else of the dataset and WITHOUT DESIGNER ? Please, how can this be done in runtime ? And how to control that the Grid be refilled, if the Dataset closed and reopened outside the Frame (where to fire TBindings.notify) ? Thx.
The following worked for me:
- Include Data.Bind.EngExt, Fmx.Bind.DBEngExt, Fmx.Bind.Grid, System.Bindings.Outputs, Fmx.Bind.Editors, Data.Bind.Components, Data.Bind.Grid and Data.Bind.DBScope in your uses clause.
Assuming your TStringGrid is named grid1 and your dataset is called qry1 :
var bds: TBindSourceDB; bdl: TBindingsList; gtd: TLinkGridToDataSource; begin bds := TBindSourceDB.Create(Self); bdl := TBindingsList.Create(Self); gtd := TLinkGridToDataSource.Create(bdl);
gtd.DataSource := bds; gtd.GridControl := Grid1;
bds.DataSet := qry1; end;
Hope this helps! (I used a TFDQuery as my dataset, but I'm sure any TDataset descendant should work fine.)