TClientDataSet: Temporary vs. permanent indices (Views: 300)
Problem/Question/Abstract: 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()): with ClientDataSet1 do begin Close; // Define the fields FieldDefs.Clear; FieldDefs.Add('Project', ftInteger, 0, True); FieldDefs.Add('Number', ftInteger, 0, False); // [..] // Define the PERMANENT index - it is saved with SaveToFile() IndexDefs.Clear; IndexDefs.Add('IProject', 'Project', [ixPrimary, ixUnique]); // Create the dataset CreateDataSet; Open; // the following temporary index is not saved // with data when using SaveToFile() AddIndex('TempIndex', 'Number;Project', [ixPrimary, ixUnique]); end { with ClientDataSet1 } |