View Issue Details

IDProjectCategoryView StatusLast Update
0024740LazarusLCLpublic2013-07-24 14:59
ReporterAnnaAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx86OSWinXP SP3 Pro RussianOS Version5.1.2600
Product Version1.1 (SVN)Product BuildLazarus-1.1-42033-fpc-2.7.1-2013 
Target VersionFixed in Version1.1 (SVN) 
Summary0024740: TTreeView.AlphaSort does not sort russian (Cyrillic) symbols alphabetically
Descriptionbefore sort : http://img7.imageshack.us/img7/5414/6zco.png
after sort : http://img163.imageshack.us/img163/5941/rfah.png

Russian alphabet http://en.wikipedia.org/wiki/Russian_alphabet
TagsNo tags attached.
Fixed in Revisionr42123
LazTarget-
Widgetset
Attached Files

Activities

Anna

2013-07-13 17:44

reporter  

Cyrillic_Alphasort_.zip (141,451 bytes)

Anna

2013-07-13 17:46

reporter   ~0068832

Last edited: 2013-07-13 17:46

View 2 revisions

'ppp' must be before 'www' (in this message i dont use russian chars , but transliteration)

Bart Broersma

2013-07-13 18:34

developer   ~0068833

You could use either OnCompare event or use CustomSort with a specified SortProc: TTreeNodeCompare.

TCustomTreeView.DefaultTreeViewSort could use Utf8CompareStr instead of AnsiCompareStr though.

Anna

2013-07-13 19:22

reporter   ~0068834

Last edited: 2013-07-13 19:30

View 4 revisions

>>use CustomSort with a specified SortProc: TTreeNodeCompare.

Does not work .
procedure TForm1.Button1Click(Sender: TObject);
function DefaultTreeViewSortEX(Node1, Node2: TTreeNode): Integer;
begin

    Result := Utf8CompareStr(Node1.Text,Node2.Text);
end;
begin
  treeview1.AlphaSort;
  treeview1.CustomSort(@DefaultTreeViewSortEX);
end;

 I get error
unit1.pas(42,46) Error: Incompatible type for arg no. 1: Got "<address of function(TTreeNode;TTreeNode):LongInt;Register>", expected "<procedure variable type of function(TTreeNode;TTreeNode):LongInt of object;Register>"

>>TCustomTreeView.DefaultTreeViewSort could use Utf8CompareStr instead of AnsiCompareStr though.

I can patch treeview.inc , but in new installer this problem will come back. So can you patch installer ?

Oh... Stupid windows code pages... It always works wrong... I hate russian!

Anton

2013-07-13 20:37

reporter   ~0068836

As far as I know, it is enough to write OnCompare handler and use AlphaSort.

procedure TForm1.TreeView1Compare(Sender: TObject; Node1, Node2: TTreeNode;
  var Compare: Integer);
begin
  Compare := UTF8CompareStr(Node1.Text, Node2.Text)
end;

Anton

2013-07-13 20:45

reporter   ~0068837

There is another question: why TCustomTreeView.DefaultTreeViewSort use by default AnsiCompareStr (lcl\include\treeview.inc:3229) if we know than Node.Text is in UTF-8 encoding?

Avishai

2013-07-13 21:34

reporter   ~0068838

There is a long discussion about sorting in this post.
http://forum.lazarus.freepascal.org/index.php/topic,17454.0.html

It seems everyone agrees that sorting is a problem in Lazarus.

Anna

2013-07-14 05:40

reporter   ~0068841

I found that reassigning all nodes by TTreeNode.Text := UTF8toANSI(TTreeNode.Text) will help to sort alphabetically. After sort you can reassign TTreeNode.Text back.

Bart Broersma

2013-07-14 11:48

developer   ~0068846

> I can patch treeview.inc , but in new installer this problem will come back.
> So can you patch installer ?

This makes no sense to me.
If I change the implementation of TCustomTreeView.DefaultTreeViewSort in trunk, it will apply in 1.2 release or next fix of 1.0 branch if this wil be merged.
The installer has nothing to do with it.

> I found that reassigning all nodes by TTreeNode.Text := UTF8toANSI(TTreeNode.Text)
> will help to sort alphabetically.
> After sort you can reassign TTreeNode.Text back.

This will fail with any Unicode Character outside your current codepage.

Bart Broersma

2013-07-17 23:23

developer   ~0068920

Please close if OK.

Anna

2013-07-24 14:59

reporter   ~0069072

Thank you very much.

Issue History

Date Modified Username Field Change
2013-07-13 17:44 Anna New Issue
2013-07-13 17:44 Anna File Added: Cyrillic_Alphasort_.zip
2013-07-13 17:46 Anna Note Added: 0068832
2013-07-13 17:46 Anna Note Edited: 0068832 View Revisions
2013-07-13 18:34 Bart Broersma Note Added: 0068833
2013-07-13 19:22 Anna Note Added: 0068834
2013-07-13 19:23 Anna Note Edited: 0068834 View Revisions
2013-07-13 19:30 Anna Note Edited: 0068834 View Revisions
2013-07-13 19:30 Anna Note Edited: 0068834 View Revisions
2013-07-13 20:37 Anton Note Added: 0068836
2013-07-13 20:45 Anton Note Added: 0068837
2013-07-13 21:34 Avishai Note Added: 0068838
2013-07-14 05:40 Anna Note Added: 0068841
2013-07-14 11:48 Bart Broersma Note Added: 0068846
2013-07-14 11:48 Bart Broersma Assigned To => Bart Broersma
2013-07-14 11:48 Bart Broersma Status new => assigned
2013-07-17 23:23 Bart Broersma Fixed in Revision => r42123
2013-07-17 23:23 Bart Broersma LazTarget => -
2013-07-17 23:23 Bart Broersma Note Added: 0068920
2013-07-17 23:23 Bart Broersma Status assigned => resolved
2013-07-17 23:23 Bart Broersma Fixed in Version => 1.1 (SVN)
2013-07-17 23:23 Bart Broersma Resolution open => fixed
2013-07-24 14:59 Anna Note Added: 0069072
2013-07-24 14:59 Anna Status resolved => closed