TClientDataSet: Temporary vs. permanent indices (Views: 101)


TClientDataSet: Temporary vs. permanent indices


On TClientDataSets, that are not connected to a provider but loaded as local text files, ('thin client in brief-case mode'), you cannot use TQuerys. You may use the Filter property to select data and use an index to sort.

This sample code shows how to create a temporary index (not saved by SaveToFile())
and how to create a permanent index (saved by SaveToFile()):

with ClientDataSet1 do
  // Define the fields
  FieldDefs.Add('Project', ftInteger, 0, True);
  FieldDefs.Add('Number', ftInteger, 0, False);
  // [..]
  // Define the PERMANENT index - it is saved with SaveToFile()
  IndexDefs.Add('IProject', 'Project', [ixPrimary, ixUnique]);
  // Create the dataset
  // the following temporary index is not saved
  // with data when using SaveToFile()
  AddIndex('TempIndex', 'Number;Project', [ixPrimary, ixUnique]);
end { with ClientDataSet1 }

<< Back to main page