Board index » delphi » Sorted TStringList.

Sorted TStringList.

Hello.
In my program I do
var S: TStringList
...

S:= TStringlist.create;
S.Sorted:= true.
....
When I check the contents of S, it is not found to be sorted :

To be specific :
I have a string with value : 'NODES', and a string with a value
'NODE_OWNER',
and 'NODE_OWNER' becomes before 'NODES' even 'NODE_OWNER' > 'NODES'

How can I fix the problem ?
(maybe because the underscore).

Thanks :o)

 

Re:Sorted TStringList.


you're wrong. Lexicography the word NODE_OWNER < NODES, so the sort is
doing it in the right way.

Quote
Eitan Mizrahi wrote:
> Hello.
> In my program I do
> var S: TStringList
> ...

> S:= TStringlist.create;
> S.Sorted:= true.
> ....
> When I check the contents of S, it is not found to be sorted :

> To be specific :
> I have a string with value : 'NODES', and a string with a value
> 'NODE_OWNER',
> and 'NODE_OWNER' becomes before 'NODES' even 'NODE_OWNER' > 'NODES'

> How can I fix the problem ?
> (maybe because the underscore).

> Thanks :o)

--
Guillermo Casta?o Acevedo <SIRIO>
Guiller...@GrupoMillennium.com
Guillermo...@Hotmail.com
WWW: http://www.GrupoMillennium.com (Gerente de Sistemas)
ICQ # 33844513
Systems and Computers Engineer

Re:Sorted TStringList.


1) If you do evaluate+modify : 'NODE_OWNER' < 'NODES' in delphi 5.0 you find
it to be false
   (even you do this in code) - try it.
2) I forgot, but I do call the command "sort", and even after that, still
there is a problem.
3) Perhaps it not that simple, and the answer for that is not for novice
programmers, but see that "sort" method calls "AnsiCompareText", which is
Windows' API function - the answer is there - but how can I solve the
problem in elegant way, and not doing something line TMyStringList, and do
my own sort...
(unless there is a bug in windows or in delphi, that I must repair myself).
4) I use windows 2000 professional, delphi 5, and my local & default
language is "English" (also "Hebrew" is installed, but it is not my locale,
and not my default language) - I'm saying this because of the function
"AnsiCompareText".

Help !!!

Quote
"Guillermo Casta?o" <Guiller...@GrupoMillennium.com> wrote in message

news:3B4AF7A3.2D841CFA@GrupoMillennium.com...
Quote
> you're wrong. Lexicography the word NODE_OWNER < NODES, so the sort is
> doing it in the right way.

> Eitan Mizrahi wrote:

> > Hello.
> > In my program I do
> > var S: TStringList
> > ...

> > S:= TStringlist.create;
> > S.Sorted:= true.
> > ....
> > When I check the contents of S, it is not found to be sorted :

> > To be specific :
> > I have a string with value : 'NODES', and a string with a value
> > 'NODE_OWNER',
> > and 'NODE_OWNER' becomes before 'NODES' even 'NODE_OWNER' > 'NODES'

> > How can I fix the problem ?
> > (maybe because the underscore).

> > Thanks :o)

> --
> Guillermo Casta?o Acevedo <SIRIO>
> Guiller...@GrupoMillennium.com
> Guillermo...@Hotmail.com
> WWW: http://www.GrupoMillennium.com (Gerente de Sistemas)
> ICQ # 33844513
> Systems and Computers Engineer

Re:Sorted TStringList.


Eitan Mizrahi <eit...@e-ntouch.com> schrieb in im Newsbeitrag:
3b4afb3d_1@dnews...

Quote

> 1) If you do evaluate+modify : 'NODE_OWNER' < 'NODES' in delphi 5.0 you
find
> it to be false
>    (even you do this in code) - try it.

Computers treat case differently, that is why there is ANSICompareText.
ANSICompareText compares without case sensitivity, so 'S' and 's' are the
same.

You should note that for english ANSI the ordinal values for the three
values 'S', '_' and 's' are:

'S' = 83
'_' = 95
's' = 115

So the equation 'NODE_OWNER' < 'NODES' will correctly result to false as 95
is not less than 85 but the comparison 'node_ower'<'nodes' will result to
true as 95 is less than 115.

ANSICompareText('node_owner, 'nodes') or ANSICompareText('NODE_OWNER',
'NODES')  will also both result to < 0.

If you find this not to be true, then a setting on your windows system is
not correct.

Kevin

Re:Sorted TStringList.


Thanks,

Because of the use ANSICompareText in sort, I had to use ANSICompareText
also to compare string in my program,
and not otherwize - (it was not obvious, but it seems to be the only
solution.
Steel I don't understand why A<B check is different from ANSICompareText.
(If  A<B compare is very common compare, isn't there any ANSICompareText,
which equivalent A<B compare - if so
what A<B checks - "terminal-font" character by character) ?

Quote
"Kevin" <ess.m...@ecostatsnono.com> wrote in message

news:3b4b0e6c_1@dnews...
Quote

> Eitan Mizrahi <eit...@e-ntouch.com> schrieb in im Newsbeitrag:
> 3b4afb3d_1@dnews...

> > 1) If you do evaluate+modify : 'NODE_OWNER' < 'NODES' in delphi 5.0 you
> find
> > it to be false
> >    (even you do this in code) - try it.

> Computers treat case differently, that is why there is ANSICompareText.
> ANSICompareText compares without case sensitivity, so 'S' and 's' are the
> same.

> You should note that for english ANSI the ordinal values for the three
> values 'S', '_' and 's' are:

> 'S' = 83
> '_' = 95
> 's' = 115

> So the equation 'NODE_OWNER' < 'NODES' will correctly result to false as
95
> is not less than 85 but the comparison 'node_ower'<'nodes' will result to
> true as 95 is less than 115.

> ANSICompareText('node_owner, 'nodes') or ANSICompareText('NODE_OWNER',
> 'NODES')  will also both result to < 0.

> If you find this not to be true, then a setting on your windows system is
> not correct.

> Kevin

Re:Sorted TStringList.


"Eitan Mizrahi" said:

Quote
> How can I fix the problem ?

YourStringList.CaseSensitive := True;

Vik

Other Threads