{TStringlist.sort 的CaseSensitive 是true或false,都是大小写不敏感。有点Bug,所以自定下自己的MyStringList;
解决办法是自己从TStringList派生一个类,并覆盖CompareStrings方法(把AnsiCompareStr换成CompareString)
}
type
TMyStringList = class(TStringList)
protected
function CompareStrings(const S1, S2: string): Integer; override;
end;
{ TMyStringList }
function TMyStringList.CompareStrings(const S1, S2: string): Integer;
begin
if CaseSensitive then
Result := CompareStr(S1, S2)
else
Result := CompareText(S1, S2);
end;
procedure TForm1.btn3Click(Sender: TObject);
var
St: TStringList;
begin
St := TMyStringList.Create;
St.Add('refundorderNo');
St.Add('refundTime');
St.CaseSensitive := True;
St.Sort;
showmessage(St.Text);
St.free;
end;