【问题标题】:Is there a compare function for file name sorting? [duplicate]是否有用于文件名排序的比较功能? [复制]
【发布时间】:2012-04-11 15:11:01
【问题描述】:

可能重复:
How to get the sort order in Delphi as in Windows Explorer?

我正在寻找一个可以像 Windows 资源管理器一样进行比较(用于文件排序)的函数。现在我正在使用CompareText 函数,但结果如下:

---------  /\  ---------
 AFile
 BFile
 _XFile
-----------------------

Windows 资源管理器以这种方式对相同的项目进行排序(这就是我想要的):

---------  /\  ---------
 _XFile
 AFile
 BFile
-----------------------

是否有这种比较的功能,还是我应该自己处理?

谢谢!

【问题讨论】:

  • RRUZ,我的错,对不起。我已经投票关闭。下次我会更仔细地检查提议的比赛。谢谢!

标签: delphi file sorting delphi-xe2 windows-explorer


【解决方案1】:

Windows 资源管理器使用StrCmpLogicalW 来比较文件名。 RTL/VCL 没有声明这个函数,所以你需要自己做。

function StrCmpLogicalW(psz1, psz2: PWideChar): Integer; stdcall;
    external 'shlwapi.dll';

【讨论】:

  • 谢谢!我一直在寻找定义此函数的位置,但仅在 Winapi.ShlObj note dont use StrCmpLogical() instead use default CompareString() 中找到
  • @Martin:当然你可以使用这个函数,即使它没有在任何.pas文件中声明。
  • @Martin 我已经包含了您现在调用该函数所需的所有内容
  • @Martin 你发现的声明,REST_NOSTRCMPLOGICAL 是一个标志,当它使用CompareString 时,它可以用来使 Explorer 在旧的 pre-XP 模式下工作。我认为这与官方确认 Explorer 使用 StrCmpLogicalW 一样接近!
  • 我已经看到并测试了它,可以按我的意愿工作。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-09
  • 2013-10-03
  • 1970-01-01
  • 1970-01-01
  • 2011-01-17
  • 2020-11-21
  • 1970-01-01
相关资源
最近更新 更多