Board index » delphi » Sorting TStringList

Sorting TStringList

Quote
Jim Blake wrote:
> I have created a TStringlist and want to sort the list. Rather than

doing a bubble sort I found the
Quote
> boolean property "Sorted" associated with TStringlist. I cannot get

the code "AllRecs.sorted := true;"  to compile. I
Quote
> get the message
> "Undeclared Identifier:'sorted'".
> I have tried using the sort function (also listed in online help) with

similiar results. What am I missing??

Are you sure 'AllRecs' is declared as TStringList and not TStrings.

if the case is like this

var
 AllRecs: TStrings;

then you'll need to typecast:

(AllRecs as TStringList).Sort
or TStringList(AllRecs).Sorted := TRUE;
or if possible just declare it so:
var
  AllRecs: TStringList;

-ThomasN

 

Re:Sorting TStringList


In article <39EEECC8.2CD99...@nycap.rr.com>, Jim Blake <jbla...@nycap.rr.com>
writes:

Quote
>I have created a TStringlist and want to sort the list. Rather than doing
>a bubble sort I found the boolean property "Sorted" associated with
>TStringlist.
>I cannot get the code "AllRecs.sorted := true;"&nbsp; to compile. I get
>the message "Undeclared Identifier:'sorted'".

>I have tried using the sort function (also listed in online help) with
>similiar results. What am I missing??

Is AllRecs a TListBox, if so the code is AllRecs.Items.Sorted := true; and
similar for Sort. The Items of a TListBox are TStrings(abstract), known in
reality to you and I as TStringLists.

Alan Lloyd
alangll...@aol.com

Other Threads