Create an index for a TClientDataSet at runtime

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 CDS1 Do
  begin
    Close;
    // Define the fields
    FieldDefs.Clear;
    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.Clear;
    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
    CreateDataSet;
    Open;
  end;

posted @ 2005-12-13 09:25  D10.天地弦  阅读(403)  评论(0编辑  收藏  举报