Cloned Source sample (desktop) (Delphi)

The ClonedSource sample demonstrates using the clone source feature to create different presentations/views of a table's data. Each presentation can have its own filter or sort order but making modifications to the data table in any one of the clones, like updating a record or inserting/deleting a record, will also update any/all other views.

Getting Started

The sample is located in C:\Users\Public\Documents\RemObjects Samples\Data Abstract for Delphi\ClonedSource.

To build it, you will need a Delphi RAD Studio and like all the samples provided with Data Abstract for Delphi you will need to be running Relativity Server with the DASamples Domain and the Simple Schema available.

Running the Sample

When run the sample presents an introduction page that describes what the sample demonstrates.

Essentially when the "Open table" button is pressed the sample downloads the data from the "Users" and "Orders" tables from the server address show in the combo box. The user interface is updated with 5 tabs.

The "Raw view" tab displays the contents of the "Orders" table without an filtering, and the sort order initially set to the Id column. You can change the sort order by clicking on the selection box and choosing one of the field names presented. To filter the table click on the selection box and choose one of the available 4 options.

 

 

 

 

Each of the remaining tabs contains a table which is a clone of "Users" table which act as a detail tables. They allow you to see that each clone can have both their own filters and sorting order.

If you make a change to the table in the "Raw View", for instance changing the Contractor for a row, you will see the change reflected through all of the clones. Likewise if you make a change to a row while in the "By Created By" view, for instance changing the Manager to something other than "Gale Dalton" you will see that change reflected in the other tables.

Examining the Code

The sample is comprised of two classes; the ClientDataModule handles all interaction with the schema and is the focus of the code below. The ClientForm handles the main user interface.

The sample makes uses of data from two tables in the "Simple" schema. First up is the "Users" table which is made up of 8 fields which are all displayed in the table. The other table is "Orders" which is made up of 11 fields.

Creating a Clone Source

The creating of the cloned tables is handled in the design view. For each table that will act as a clone, the source table (here tbl_Users) is passed to the CloneSource property of a subclass of TDADataTable, this sample uses the TDAMemDataTable class.

From this point the clone can have its own filtering and sorting order.

How to apply a Filter & Sorting

To set a filter pass a string containing the filtering condition to the Filter property of TDADataTable (or a subclass). Once the filter is active, only those records that match the condition will be visible. To enable the filter, pass True to the Filtered property.

The IndexFieldNames property allows you to define which of the table fields should be used as the index or sort field. To use it pass the field name as a string to the property.

procedure TClientDataModule.ApplyFilter(aTable: TDAMemDataTable; aFilter,
  aSorting: String);
begin
  aTable.DisableControls;
  try
    aTable.IndexFieldNames := aSorting;
    aTable.Filter := aFilter;
    aTable.Filtered := aTable.Filter <> '';
  finally
    aTable.EnableControls;
  end;
end;