自己看看,应该少作修改就能用了。它自己的是对字符串的排序,要是数字,就要这样
function TFrmconverter.CompareValue(s1,s2:real):integer;//升序
begin
if s1 > s2 then result:=1
else result:=0;
end;
procedure TFrmconverter.viewFileColumnClick(Sender: TObject;
Column: TListColumn);
begin
nSortCol := Column.Index;
Viewfile.AlphaSort;
end;
procedure TFrmconverter.viewFileCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
var
RR1,RR2:Real;
begin
if nSortCol = 0 then
Compare := CompareStr (Item1.Caption, Item2.Caption);//自带的对字符串的排序
//else
//Compare := CompareStr (Item1.SubItems [nSortCol - 1],
// Item2.SubItems [nSortCol - 1]);
if (nSortCol=3) or (nSortCol=5 )or (nSortCol=6) or (nSortCol=11) then //!@选择对应的数字列项
begin
if trim(item1.SubItems[nsortcol-1])='' then RR1:=0
else RR1:=strtofloat(trim(copy(item1.SubItems[nsortcol-1],1,length(item1.SubItems[nsortcol-1])-2)));//去掉多余的后两位字符
if trim(item2.SubItems[nsortcol-1])='' then RR2:=0
else RR2:=strtofloat(trim(copy(item2.SubItems[nsortcol-1],1,length(item2.SubItems[nsortcol-1])-2)));
//升序
compare:=CompareValue(RR1,RR2)
end;