|
发表于 2020-4-25 14:00:01
|
显示全部楼层
傻子问个傻问题:
============
聪明人回答聪明问题。 :) :)
function Compare(List: TStringList; Index1, Index2: Integer): Integer;
begin
if List[Index1] = '0' then
if List[Index2] <> '0' then
Result := 1
else
Result := 0
else
if List[Index2] = '0' then
Result := -1
else
Result := CompareText(List[Index1], List[Index2]);
end;
procedure TFormDemo.ButtonDemoClick(Sender: TObject);
var
SL: TStringList;
begin
SL := TStringList.Create;
SL.Add('0');
SL.Add('4');
SL.Add('1');
SL.Add('0');
SL.Add('0');
SL.Add('5');
SL.Add('3');
SL.Add('2');
SL.CustomSort(@Compare);
ListBox.Items := SL; //看看结果
end;
//结果
======
1
2
3
4
5
0
0
0
|
|