我们都知道,Windows资源管理器可以对文件名按时间排序,但是在BCB里的“Win3.1”面板里的FileListBox控件中,如何实现对文件名按时间排序呢?例如我的文件本来应该排列为: LN1.txt
LN2.txt
LN3.txt
LN10.txt
LN20.txt
LN30.txt但在FileListBox控件中却排列为: LN1.txt
LN10.txt
LN2.txt
LN20.txt
LN3.txt
LN30.txt如何才能满足我的要求呢?请高手指点,谢谢!
LN2.txt
LN3.txt
LN10.txt
LN20.txt
LN30.txt但在FileListBox控件中却排列为: LN1.txt
LN10.txt
LN2.txt
LN20.txt
LN3.txt
LN30.txt如何才能满足我的要求呢?请高手指点,谢谢!
解决方案 »
- dbgrideh 统计和的问题
- 请问 如何 用 程序 控 钱箱 打开 ?????????????????????????????????? 急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 如果判断一个对象已经被释放资源了?
- 请教各位 我用的是Delphi7 如何可以找到 QuickRep 生成报表控件 谢谢了!!
- 如何根据类名创建类实例?
- ★★★★★★ 如何显示tif格式的图片?
- 远程线程跳板---实现木马的深度隐藏技术!!!!!!!!!!!!!!!!
- 在stringGrid.cell中怎样换行?
- delphi中有拔号控件吗?麻烦您给出一个例子。
- 关于sql的问题
- 问一个关于乘除法的问题.为什么一直编译无法通过?
- 求助!ExpressPrinting.System怎么打印出来的图片不是一比一的啊?怎样才能用2个文本控件达到分行效果啊?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, FileCtrl;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; TMyFileListBox = class(TFileListBox)
public
constructor Create(AOwner: TComponent); override;
protected
procedure ReadFileNames;override;
end;var
Form1: TForm1;implementation{$R *.dfm}
{ TMyFileListBox }constructor TMyFileListBox.Create(AOwner: TComponent);
begin
inherited;
Sorted := False; //禁止它自动排序
end;procedure TMyFileListBox.ReadFileNames;
var
AttrIndex: TFileAttr;
I: Integer;
FileExt: string;
MaskPtr: PChar;
Ptr: PChar;
AttrWord: Word;
FileInfo: TSearchRec;
SaveCursor: TCursor;
Glyph: TBitmap;
DateList :TStringList; //时间列表
const
Attributes: array[TFileAttr] of Word = (faReadOnly, faHidden, faSysFile,
faVolumeID, faDirectory, faArchive, 0); procedure QuickSort(L, R: Integer); //快速排序
var
I, J: Integer;
P: Integer;
begin
I := L;
J := R;
P := StrToInt(DateList[(L + R) shr 1]);
repeat
while StrToInt(DateList[I]) < P do Inc(I);
while StrToInt(DateList[J]) > P do Dec(J);
if I <= J then
begin
Items.Exchange(I, J);
DateList.Exchange(I, J);
Inc(I);
Dec(J);
end;
until I > J;
if L < J then
QuickSort(L, J);
if I < R then
QuickSort(I, R);
end;begin
DateList := TStringList.Create;
AttrWord := DDL_READWRITE;
if HandleAllocated then
begin
for AttrIndex := ftReadOnly to ftArchive do
if AttrIndex in FileType then
AttrWord := AttrWord or Attributes[AttrIndex];
ChDir(FDirectory);
Clear;
I := 0;
SaveCursor := Screen.Cursor;
try
MaskPtr := PChar(FMask);
while MaskPtr <> nil do
begin
Ptr := StrScan (MaskPtr, ';');
if Ptr <> nil then
Ptr^ := #0;
if FindFirst(MaskPtr, AttrWord, FileInfo) = 0 then
begin
repeat
if (ftNormal in FileType) or (FileInfo.Attr and AttrWord <> 0) then
if FileInfo.Attr and faDirectory <> 0 then
begin
I := Items.Add(Format('[%s]',[FileInfo.Name]));
if ShowGlyphs then
Items.Objects[I] := DirBMP;
end
else
begin
FileExt := AnsiLowerCase(ExtractFileExt(FileInfo.Name));
Glyph := UnknownBMP;
if (FileExt = '.exe') or (FileExt = '.com') or
(FileExt = '.bat') or (FileExt = '.pif') then
Glyph := ExeBMP;
I := Items.AddObject(FileInfo.Name, Glyph);
DateList.Append(IntToStr(FileInfo.Time));
end;
if I = 100 then
Screen.Cursor := crHourGlass;
until FindNext(FileInfo) <> 0;
FindClose(FileInfo);
end;
if Ptr <> nil then
begin
Ptr^ := ';';
Inc (Ptr);
end;
MaskPtr := Ptr;
end;
QuickSort(0,Items.Count - 1 );
finally
Screen.Cursor := SaveCursor;
DateList.Free;
end;
Change;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var a: TMyFileListBox;
begin
a := TMyFileListBox.Create(self);
a.FileType :=[ftReadOnly,ftHidden,ftSystem,ftNormal];
a.Mask := 'c:\Windows\System32\*.*';
a.Parent := Form1;
a.Width := 200;
a.Height := 200;
end;end.