我想要反转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;
解决方法
创建索引时使用TIndexDef.Options.它们不能用于尝试影响现有索引.见
documentation(强调我的):
When creating a new index,use Options to specify the attributes of the index. Options can contain zero or more of the TIndexOption constants ixPrimary,ixUnique,ixDescending,ixCaseInsensitive,and ixExpression.
When inspecting the definitions of existing indexes,read Options to determine the option(s) used to create the index.
您需要使用ixDescending值集创建单独的索引.然后,您只需更改IndexName属性即可来回切换.