反转ClientDataSet的索引上的顺序 [英] Reverse the order on an index for a ClientDataSet

查看:130
本文介绍了反转ClientDataSet的索引上的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要颠倒TClientDataSet中索引的顺序,下面的代码看起来应该做的但是什么都不做。有没有一种很好的方法来反转索引的顺序?

I'm wanting to reverse the order of an index in a TClientDataSet, the following code looks like it should do the trick but does nothing. Is there a nice way to reverse the order of an index?

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 。它们不能用于尝试和影响现有索引。请参阅文档强调我的):

TIndexDef.Options are used when creating the indexes. They can't be used to try and affect an existing index. See the documentation (emphasis mine):


创建新索引时,使用选项指定索引的属性。选项可以包含零个或多个TIndexOption常量ixPrimary,ixUnique,ixDescending,ixCaseInsensitive和ixExpression。

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 属性即可来回切换。

You'll need to create a separate index with the ixDescending value set. You can then switch back and forth by just changing the IndexName property.

这篇关于反转ClientDataSet的索引上的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆