Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

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

  • 2 Comments sorted by Votes Date Added
  • 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.