Synchronizing Tables

From RAD Studio
Jump to: navigation, search

Go Up to Using Table Type Datasets


If you have two or more datasets that represent the same database table but do not share a data source component, then each dataset has its own view on the data and its own current record. As users access records through each datasets, the components' current records will differ.

If the datasets are all instances of TTable, or all instances of TIBTable, or all client datasets, you can force the current record for each of these datasets to be the same by calling the GotoCurrent method. GotoCurrent sets its own dataset's current record to the current record of a matching dataset. For example, the following code sets the current record of CustomerTableOne to be the same as the current record of CustomerTableTwo:

CustomerTableOne.GotoCurrent(CustomerTableTwo);
CustomerTableOne->GotoCurrent(CustomerTableTwo);

Tip: If your application needs to synchronize datasets in this manner, put the datasets in a data module and add the unit for the data module to the uses clause of each unit that accesses the tables.

To synchronize datasets from separate forms, you must add one form's unit to the uses clause of the other, and you must qualify at least one of the dataset names with its form name. For example:

CustomerTableOne.GotoCurrent(Form2.CustomerTableTwo);
CustomerTableOne->GotoCurrent(Form2->CustomerTableTwo);

See Also