Ali*_*ter 6 delphi indexing tclientdataset
我想要反转TClientDataSet中索引的顺序,下面的代码看起来应该做的伎俩但什么都不做.有没有一种很好的方法来扭转索引的顺序?
procedure TForm8.Button1Click(Sender: TObject);
var
index: TIndexDef;
begin
index := ClientDataSet1.IndexDefs.Find('LengthIndex');
if ixDescending in index.Options then
index.Options := index.Options - [ixDescending]
else
index.Options := index.Options + [ixDescending];
end;
Run Code Online (Sandbox Code Playgroud)
TIndexDef.Options在创建索引时使用.它们不能用于尝试影响现有索引.参见文档(强调我的):
创建新索引时,使用"选项"指定索引的属性.选项可以包含零个或多个TIndexOption常量ixPrimary,ixUnique,ixDescending,ixCaseInsensitive和ixExpression.
检查现有索引的定义时,请阅读"选项"以确定用于创建索引的选项.
您需要使用ixDescending值集创建单独的索引.然后,您只需更改IndexName属性即可来回切换.