Delphi 字符串、文件路径 排序算法


本文整理自网络,侵删。

 


//正序
function SortItem(List: TStringList; Index1, Index2: Integer): Integer;
var A1, A2: String;
    Dir1, Dir2: String;
    Name1, Name2: String;
begin//delphitop.com
  A1 := List[Index1];
  A2 := List[Index2];

  Dir1 := ExtractFilePath(A1);
  Dir2 := ExtractFilePath(A2);

  Name1 := ExtractFileName(A1);
  Name2 := ExtractFileName(A2);

  if Dir1 = Dir2 then
    Result := AnsiCompareText(Name1, Name2)
  else
    Result := AnsiCompareText(Dir1, Dir2);
end;

//倒序
function SortItem2(List: TStringList; Index1, Index2: Integer): Integer;
var A1, A2: String;
    Dir1, Dir2: String;
    Name1, Name2: String;
begin
  A1 := List[Index1];
  A2 := List[Index2];
  //delphitop.com
  Dir1 := ExtractFilePath(A1);
  Dir2 := ExtractFilePath(A2);

  Name1 := ExtractFileName(A1);
  Name2 := ExtractFileName(A2);

  if Dir1 = Dir2 then
    Result := AnsiCompareText(Name2,Name1 )
  else
    Result := AnsiCompareText(Dir2, Dir1);
end;


procedure TForm1.Button1Click(Sender: TObject);
var
FList: TStringList;
begin
FList:=TStringList.Create;
FList.Text:=Memo1.Text;
FList.CustomSort(SortItem);
Memo1.Text:=FList.Text;
end;

相关阅读 >>

Delphi中message消息的使用方法

delphDelphi chromium embedded 清除指定链接浏览器缓存、cookies

orangeui作者开源作品

Delphi2007-Delphi2010 程序不出现在任务栏的方法

Delphi 病毒

Delphi byte数组根据utf8 转换为string

Delphi使用xmlhttp组件代码

Delphi判断电脑连接到 internet 了吗?

Delphi 读取文件的md5值

Delphi中的字符串

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...