Delphi 阿尔法排序网格

Delphi 阿尔法排序网格,delphi,Delphi,如何在Delphi中对给定列的表单上的stringgrid进行alpha排序?TStringGrid没有内置的排序功能,因此您需要自己进行排序。就我个人而言,我使用一些通用排序代码,可以对任何提供了比较函数和交换函数的内容进行排序: type TCompareIndicesFunction = function(Index1, Index2: Integer): Integer of object; TExchangeIndicesProcedure = procedure(Index1

如何在Delphi中对给定列的表单上的stringgrid进行alpha排序?

TStringGrid没有内置的排序功能,因此您需要自己进行排序。就我个人而言,我使用一些通用排序代码,可以对任何提供了比较函数和交换函数的内容进行排序:

type
  TCompareIndicesFunction = function(Index1, Index2: Integer): Integer of object;
  TExchangeIndicesProcedure = procedure(Index1, Index2: Integer) of object;

procedure Sort(const First, Last: Integer; Compare: TCompareIndicesFunction; Exchange: TExchangeIndicesProcedure);
begin
  //insert search algorithm here
end;
您可以查看Generics.Collections.TArray.Quicksort是如何实现的,以了解如何填充上面缺少的代码


重要的一点是,作为对象方法的
Compare
Exchange
函数包含如何比较字符串网格中的项,然后如何交换这些项的知识。

TStringGrid没有内置的排序功能,因此您需要自己滚动。就我个人而言,我使用一些通用排序代码,可以对任何提供了比较函数和交换函数的内容进行排序:

type
  TCompareIndicesFunction = function(Index1, Index2: Integer): Integer of object;
  TExchangeIndicesProcedure = procedure(Index1, Index2: Integer) of object;

procedure Sort(const First, Last: Integer; Compare: TCompareIndicesFunction; Exchange: TExchangeIndicesProcedure);
begin
  //insert search algorithm here
end;
您可以查看Generics.Collections.TArray.Quicksort是如何实现的,以了解如何填充上面缺少的代码


重要的一点是,作为对象方法的
Compare
Exchange
函数包含如何比较字符串网格中的项,然后如何交换它们的知识。

字符串列表没有列。它们只是一个简单的字符串列表。请更具体地说明您想要什么。VCL stringlist在两列中填充了一些数据您问了两个相同的问题。您想知道如何指定自定义排序比较函数。字符串列表没有列。你是什么意思?数据来自哪里?您是否考虑过使用虚拟控件,例如详细信息视图中的虚拟列表视图?这允许您对底层数据进行排序,并让演示文稿反映这些数据,而无需将数据插入或移出控制。或者,您甚至可以使用排序间接寻址进行额外级别的间接寻址!!字符串列表没有列。它们只是一个简单的字符串列表。请更具体地说明您想要什么。VCL stringlist在两列中填充了一些数据您问了两个相同的问题。您想知道如何指定自定义排序比较函数。字符串列表没有列。你是什么意思?数据来自哪里?您是否考虑过使用虚拟控件,例如详细信息视图中的虚拟列表视图?这允许您对底层数据进行排序,并让演示文稿反映这些数据,而无需将数据插入或移出控制。或者,您甚至可以使用排序间接寻址进行额外级别的间接寻址!!