RAD Studio
ContentsIndex
PreviousUpNext
Changing the Associated Dataset at Runtime

In Associating a Data Control with a Dataset, the datasource was associated with its dataset by setting the DataSet property at design time. At runtime, you can switch the dataset for a data source component as needed. For example, the following code swaps the dataset for the CustSource data source component between the dataset components named Customers and Orders:

with CustSource do begin
  if (DataSet = Customers) then
    DataSet := Orders
  else
    DataSet := Customers;
end;

 

if (CustSource->DataSet == Customers)
  CustSource->DataSet = Orders;
else
  CustSource->DataSet = Customers;

You can also set the DataSet property to a dataset on another form to synchronize the data controls on two forms. For example:

procedure TForm2.FormCreate (Sender : TObject);
begin
  DataSource1.Dataset := Form1.Table1;
end;

 

void __fastcall TForm2::FormCreate(TObject *Sender)
{
  DataSource1->DataSet = Form1->Table1;
}
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!