Re:Howto sort '+', '-', '*', '/',... with Delphi3
Quote
Denis Bouhineau wrote...
>Hi'
> I want to sort the following string '+', '-', '*', '/', '->', '|' ,
>'<<' and '='. So I've imagined using TstringList :
>begin
>WL := TStringList.Create;
>WL.Add('+');WL.Add('-');WL.Add('*');WL.Add('/');
>WL.Add('=');WL.Add('->');WL.Add('|');WL.Add('<<');
>MotsClesExistants.sorted := True;
>end;
>But the result is :
>'-', '*', '/', '|', '+', '<<', '=', '->'
>here are ascii-code for the first letter :
>2d 2a 2f 7c 2b 3c 3d 2d
>Do you understand the order ? How to obtain ascii-order ?
I get exactly the same sorting order as you do. I'm using the english
version of D2 on a german Windows 95(A). I suppose you have a
different configuration. I expected it to be a code page problem
first, but then we would have had slightly different results. The
problem also appears in a list box. The same order again.
So I looked at the sources a bit. The TStringList and other lists seem
to use a quick sort routine to sort everything out. The quick sort
routine uses AnsiCompareText to compare the strings. I suppose the
problem lies in AnsiCompareText or perhaps in TStringList.QuickSort.
Delphi help says:
|Declaration
|
|function AnsiCompareText(const S1, S2: string): Integer;
|
|Description
|
|AnsiCompareText compares S1 to S2, without case sensitivity. The
compare operation is |controlled by the currently installed language
driver. The return value is the same as for |CompareStr.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The sources show that AnsiCompareText uses:
Result := CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
PChar(S1), Length(S1), PChar(S2), Length(S2)) - 2;
So the problem is really the installed language driver
So blame M$.
Rudy Velthuis