DelphiFAQ Home Search:

Create an index for a TClientDataSet at runtime


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

When I had to create an index for a in-memory table, I got the
error message 'No active index' when accessing the index e.g. with FindKey().

I had originally created the index with the property IndexName
and finally found out that this did not select my index.
Selecting the index by the property IndexFieldNames worked fine,
as the following source shows.

This is also an example how to create a memory table..

  With ClientDataSet1 Do
    // Define the fields
    FieldDefs.Add ('Project', ftInteger, 0, True);
    FieldDefs.Add ('Module',  ftString, 60, False);
    FieldDefs.Add ('FuncName',ftString, 60, False);
    FieldDefs.Add ('FuncDate',ftDate,    0, False);
    FieldDefs.Add ('FuncCRC', ftString,  2, False);
    FieldDefs.Add ('Programmer', ftString, 32, False);
    // Define the index
    IndexDefs.Add ('IProject', 'Project;Module;FuncName',
                   [ixPrimary, ixUnique]);
    // this seems not to do anything
    IndexName := 'IProject';
    // this does work
    IndexFieldNames := 'Project;Module;FuncName';
    // Create the dataset
  End { with ClientDataSet1 }


2006-01-11, 15:16:16
anonymous from United States  
2009-10-06, 02:21:20
anonymous from Italy  
IndexDefs.Add ('IProject', 'Project;Module;FuncName',
[ixPrimary, ixUnique]);

Try this:
IndexDefs.Add ('IProject', ('Project;Module;FuncName'),[ixPrimary, ixUnique]);



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:

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.

photo Add a picture: