DelphiFAQ Home Search:

TClientDataSet: Temporary vs. permanent indices

 

comments2 comments. Current rating: 5 stars (2 votes). Leave comments and/ or rate it.

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 }
You don't like the formatting? Check out SourceCoder then!

Comments:

2006-01-11, 15:20:33
anonymous from United States  
rating
2006-01-30, 21:00:57
anonymous from United States  
rating

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.