Dynamic Select sample (desktop) (Delphi)

The Dynamic Select sample demonstrates how to use Dynamic Select to selectively retrieve data from a table in an instance of Relativity Server by limited the fields retrieved to only those that are needed.

There are a couple of different methods available in Data Abstract for Delphi to use the Dynamic Select feature. This sample demonstrates the simpler, although not so obvious, approach of removing the un-needed fields from the Data Table before passing the table to the server.

The other approach requires some more boilerplate code to set up, using an instance of TableRequestInfoV5, but it is a bit more straightforward.

Getting Started

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

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 retrieves all of the records from the "Clients" table of the "Simple" schema. However rather than including all of the fields in a row, Dynamic Select is used to specify the fields the fields that should be returned.

The UI is comprised of a table that displays the data, and a toolbar that has a combo box for the server address and three buttons. "Fill" will retrieve the data from the server; you will only need this if you start Relativity Server after you start the sample as the sample will attempt to automatically retrieve the data. "Delete" will delete the currently selected row. Finally "Apply Changes" will send any changes to the local data back to the server.

Double clicking on a field allows you to edit the data in that field.

Examining the Code

The sample is comprised of two classes, ClientDataModule which handles the interaction with the schema and ClientForm that handles the UI interaction.

The "Clients" table in the "Simple" schema of the "DASamples" domain is comprised of 10 fields which the sample filters down to just 6.

Retrieving data using Dynamic Select

The focus here is the TClientDataModule.FillTable procedure of ClientDataModule.

The first step in this sample is to ensure that that Dynamic Select is turned on in the TDARemoteDataAdapter by assigning True to the DynamicSelect property.

As mentioned at the beginning of this page, this sample uses the approach of only adding the fields we are interested in to the table. This is handled in this sample by passing an array of field names as strings to the ConfigureTableForDynamicSelect procedure which will reconfigure the table for us.

The ConfigureTableForDynamicSelect procedure can be found in fClientDataModule.pas and is a helper procedure that takes two arguments; the first an instance of TDADataTable and the second argument is the array of the fields we want to retrieve. The procedure empties the table of all existing fields, and then adds a new field, which are instances of TDAField, for each element of the array of field names and assigns the field name to the Name. This is important as the field names will be used by the server to decide what data it is returning.

procedure ConfigureTableForDynamicSelect(aTable: TDADataTable; aDynamicSelect: array of string);
var
  i: integer;
  lField: TDAField;
begin
  aTable.Close;
  aTable.Fields.Clear;
  for I := Low(aDynamicSelect) to High(aDynamicSelect) do begin
    lField := aTable.Fields.Add;
    lField.Name := aDynamicSelect[i];
  end;
end;

Finally we call the Fill procedure of TDARemoteDataAdapter passing it the table object, a False to indicate that cursor should not be saved, and True that the schema should be included. Note there is an optional fourth boolean argument which has a default value of false and does not need to be supplied.

This then retrieves the required table data and it will be displayed on the table of the user interface.

TDABaseDataAdapter(tbl_Clients.RemoteDataAdapter).DynamicSelect:=True;

ConfigureTableForDynamicSelect(tbl_Clients, ['ClientID', 'ClientName', 'ClientEmail', 'ClientPassword', 'ClientPhone', 'ClientAddress']);
RemoteDataAdapter.Fill([tbl_Clients],False,True);