This forum is temporaily read-only. All existing discussions remain available for reference. For new questions, bug reports or support requests, please contact us at mail@lmdsupport.com.

Sort items

Hello,
I want to sort following items.
ElListBox1->Items->Clear();
ElListBox1->Items->Add(UnicodeString("A"));
ElListBox1->Items->Add(UnicodeString("C"));
ElListBox1->Items->Add(UnicodeString("+"));
ElListBox1->Items->Add(UnicodeString("E"));
ElListBox1->Items->Add(UnicodeString("-"));
ElListBox1->Items->Add(UnicodeString(" "));
ElListBox1->Items->Add(UnicodeString("-A"));
ElListBox1->Sorted=true;

the result is 
-

+
A
-A
C
E

the expedted result is
 
+
-
-A
A
C
E

What is wrong on my code?


Comments

  • Unfortuntely, this seems to be a Delphi bug. The following code, which does not use LMD components at all, produces the same result:

    procedure TForm17.Button1Click(Sender: TObject);
    var
      buf: TStringList;
    begin
      buf := TStringList.Create;
      try
        buf.Add('A');
        buf.Add('C');
        buf.Add('+');
        buf.Add('E');
        buf.Add('-');
        buf.Add(' ');
        buf.Add('-A');
        
        buf.Sorted := True;

        Memo1.Lines.Assign(buf);
      finally
        buf.Free;
      end;
    end;
  • This may also be a way in which Windows sorts strings. As a workaround you can use the following code line before sorting:

    buf.UseLocale := False;
Sign In or Register to comment.