关于文件排序?(200分)

C

cuiiq

Unregistered / Unconfirmed
GUEST, unregistred user!
我想对一系列文件进行排序,其中包括按文件名排序,按日期排序,按大小排序等等,其中每一种又分为正序和反序两种。如果对每一种都写一个过程的话有点太复杂,我初步设想建立两个过程(正排和反排),然后给它们传递参数确定是按名称,日期还是大小排序,但这似乎必须用函数作为传递参数,我实在搞不定,请各位大虾帮帮忙。
 
你要做资源管理器吗?
 
关键是用什么排?如果用listview的话就好办,它有专门排序的事件和属性,可以用ondata和oncompare...
 
不用函数呀, 只要判断比较的类型是什么以及是否是降序就可以了:)
用快速排序法吧, 很简单.
 
hansong:我用的确实是listview,你能说的更具体一点吗?
 
看看ListView的OnCompare事件,他会传过来2个需要比较大小的item,你自己
用自己的法则判断大小即可.
 
用example改的!

var
Form1: TForm1;
ColumnToSort:integer=0;
SortStyle:Boolean=true;

implementation

{$R *.DFM}

procedure TForm1.ListView1Compare(Sender: TObject
Item1, Item2: TListItem;
Data: Integer
var Compare: Integer);
var
ix: Integer;
begin
if ColumnToSort = 0 then
Compare := CompareText(Item1.Caption,Item2.Caption)
else begin
ix := ColumnToSort - 1;
Compare := CompareText(Item1.SubItems[ix],Item2.SubItems[ix]);
end;
if SortStyle then
Compare:=-Compare;
end;

procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
begin
ColumnToSort := Column.Index;
(Sender as TCustomListView).AlphaSort;
SortStyle:=not SortStyle;
end;
 
多人接受答案了。
 
顶部