Bug in Listview.Sort

Discuss GUI programming with the RapaGUI plugin here
Post Reply
pecaN
Posts: 111
Joined: Thu Jun 10, 2010 4:15 pm

Bug in Listview.Sort

Post by pecaN » Thu Nov 28, 2019 9:43 pm

Hi,
maybe i got this feature wrong but look at this. I've got a listview like this :

g
a
z
f
ch

When I set the column as sortable and apply the Sort function, I get this :

a
ch
f
g
z

so it seems that RapaGUI handles "ch" as "c"...

the same goes for numbers, I've got this :

48
92
23
14
6

and after sorting I get :

14
23
48
6
92

So it really seems that RapaGUI handles only the first char of the string when sorting...

pecaN

pecaN
Posts: 111
Joined: Thu Jun 10, 2010 4:15 pm

Re: Bug in Listview.Sort

Post by pecaN » Thu Nov 28, 2019 10:02 pm

just for sure, I'm adding that in Hollywood itself sorting works correctly, so for example g,a,b,ch,v sorts as a,b,g,ch,v while RapaGUI outputs a,b,ch,g,v

User avatar
airsoftsoftwair
Posts: 3208
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Bug in Listview.Sort

Post by airsoftsoftwair » Tue Dec 03, 2019 4:23 pm

pecaN wrote:
Thu Nov 28, 2019 9:43 pm
Hi,
maybe i got this feature wrong but look at this. I've got a listview like this :

g
a
z
f
ch

When I set the column as sortable and apply the Sort function, I get this :

a
ch
f
g
z

so it seems that RapaGUI handles "ch" as "c"...
Yes, and that's correct. What else do you expect? Sorting is done alphabetically, so "ch" definitely has to come before "f", "g", and "z". Everything else wouldn't really make much sense...
pecaN wrote:
Thu Nov 28, 2019 10:02 pm
just for sure, I'm adding that in Hollywood itself sorting works correctly, so for example g,a,b,ch,v sorts as a,b,g,ch,v while RapaGUI outputs a,b,ch,g,v
Can't reproduce this here. Hollywood's Sort() function yields exactly the same results as RapaGUI, e.g.

Code: Select all

a = {"g", "a", "z", "f", "ch"}
Sort(a)
For Local k = 0 To ListItems(a) - 1 Do DebugPrint(a[k])
prints

Code: Select all

a
ch
f
g
z
If you get different results, please post your code and include your platform.

pecaN
Posts: 111
Joined: Thu Jun 10, 2010 4:15 pm

Re: Bug in Listview.Sort

Post by pecaN » Tue Dec 03, 2019 10:25 pm

OK, this is interesting!

First, sorry for such a stupid typo I made : I wrote that table {g,a,z,f,ch) is sorted as a,ch,f,g,z but that's wrong!!!

Really, when on my Win10 (Czech localization) + Hollywood 8 I use exactly the same code as you did :

a = {"g", "a", "z", "f", "ch"}
Sort(a)
For Local k = 0 To ListItems(a) - 1 Do DebugPrint(a[k])

I REALLY get it sorted as a,f,g,ch,z !!!! But it's obviously not a bug, it seems to be something with localization as I totally forgot that Czech and other Eastern European alphabets do have "ch" as STANDALONE character which is between "h" and "i" so the alphabet goes e,f,g,h,ch,i,j... etc....

So in Hollywood itself this works perfectly for us Easterns but when I use this characters as items in a listview column (RapaGUI 1.2) :

g
a
z
f
ch

and then I sort it, I get as you write

a
ch
f
g
z

So i was just curious why Hollywood and RapaGUI sort it in a different way, both use UTF-8 encoding, maybe it's because of different font?
but I can live with it, that's just a curse of being an Eastern European so it can be solved quite easily :-)

BUT!! there's still the problem with sorting numbers in RapaGUI as I wrote!!

when I have a table of numbers in Hollywood table={48, 2, 23, 14, 6} it gets sorted right = 2,6,14,23,48

BUT when I have these numbers as listview items in RapaGUI :

48
2
23
14
6

and I sort the column I get this :

14
2
23
48
6

which clearly is wrong....


Sorry for such a long post but sorting a listview is a VITAL feature for listview..... pecaN

User avatar
airsoftsoftwair
Posts: 3208
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Bug in Listview.Sort

Post by airsoftsoftwair » Sun Dec 08, 2019 2:16 pm

So i was just curious why Hollywood and RapaGUI sort it in a different way, both use UTF-8 encoding, maybe it's because of different font?
No, that's clearly a bug in RapaGUI. Will be fixed...
BUT!! there's still the problem with sorting numbers in RapaGUI as I wrote!!

when I have a table of numbers in Hollywood table={48, 2, 23, 14, 6} it gets sorted right = 2,6,14,23,48

BUT when I have these numbers as listview items in RapaGUI :

48
2
23
14
6

and I sort the column I get this :

14
2
23
48
6

which clearly is wrong....
No, it's not. When using strings, Hollywood will always sort alphabetically, e.g.

Code: Select all

table={48, 2, 23, 14, 6}  ; table contains numbers = numerical sort
Sort(table)  ; will result in 2,6,14,23,48
table={"48", "2", "23", "14", "6"} ; table contains strings = alphabetical sort
Sort(table)  ; will result in "14", "2", "23", "48", "6"
Listviews, of course, will always sort the items alphabetically as well because they store their items as strings. If you want to have numeric sorting for listviews, you need to implement this using Listview.CompareItems.

pecaN
Posts: 111
Joined: Thu Jun 10, 2010 4:15 pm

Re: Bug in Listview.Sort

Post by pecaN » Sun Dec 08, 2019 8:55 pm

Great, thanks :-)

User avatar
airsoftsoftwair
Posts: 3208
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Bug in Listview.Sort

Post by airsoftsoftwair » Wed Dec 11, 2019 5:23 pm

Code: Select all

- Fix [Windows/macOS/Linux]: Listview sorting didn't always work correctly for non-ISO-8859-1 languages

Post Reply