RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDataSource.DataSet Property

Specifies the dataset for which the data source component serves as a conduit to data-aware controls or other datasets.

Pascal
property DataSet: TDataSet;
C++
__property TDataSet DataSet;

Set DataSet to the name of an existing dataset component either at design time, or at runtime. By changing the value of DataSet at runtime an application can effectively use the same data-aware controls to display and edit data in different datasets. 

DataSource.DataSet := ClientDataSet1; 

DataSource->DataSet = ClientDataSet1;

Note: To link a dataset that resides in a data module to a form at design-time, choose File | Use unit (Delphi) or File | Include unit header (C++).
 

Delphi Examples: 

 

{
The following example copies the selected rows in a db grid
to a list box.  Set the db grid Options dgRowSelect,
dgAlwaysShowSelection and dgMultiSelect to True.  Make a
multiple selecton using the CNTL key.  This example requires
a TDataSet associated with a TDataSource and a TDBGrid.}
procedure TForm1.Button2Click(Sender: TObject);
var
  i, j: Integer;
  s: string;
begin
  if DBGrid2.SelectedRows.Count>0 then
    with DBGrid2.DataSource.DataSet do
      for i:=0 to DBGrid2.SelectedRows.Count-1 do
      begin
        GotoBookmark(pointer(DBGrid2.SelectedRows.Items[i]));
        for j := 0 to FieldCount-1 do
        begin
          if (j>0) then s:=s+', ';
          s:=s+Fields[j].AsString;
        end;
        Listbox1.Items.Add(s);
        s:= '';
      end;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!