Author: Tomas Rutkauskas
TClientDataSet: Temporary vs. permanent indices
Answer:
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()):
1
2 with ClientDataSet1 do
3 begin
4 Close;
5 // Define the fields
6 FieldDefs.Clear;
7 FieldDefs.Add('Project', ftInteger, 0, True);
8 FieldDefs.Add('Number', ftInteger, 0, False);
9 // [..]
10 // Define the PERMANENT index - it is saved with SaveToFile()
11 IndexDefs.Clear;
12 IndexDefs.Add('IProject', 'Project', [ixPrimary, ixUnique]);
13 // Create the dataset
14 CreateDataSet;
15 Open;
16 // the following temporary index is not saved
17 // with data when using SaveToFile()
18 AddIndex('TempIndex', 'Number;Project', [ixPrimary, ixUnique]);
19 end { with ClientDataSet1 }
|