Board index » cppbuilder » BCB3 missing implementation of: TStringList -> CustomSort( )

BCB3 missing implementation of: TStringList -> CustomSort( )


2003-11-04 02:59:43 AM
cppbuilder101
hi dear builders,
I got one problem,
Remy gave me a nice piece of code the handles a sorting-routine..
the problem is, that I use BCB 3 Pro. and there isn't an implementation
of ->CustomSort( )
can someone tell me if there is an implementation of CustomSort ( ) or maybe
something
similar to it for BCB 3 ???
Thanks for any help...
Oren
/**********************************************************/
int __fastcall SortCallback(TStringList *List, int Index1, int Index2)
{
AnsiString Name1 = (StrRScan(List->Strings[Index1].c_str(), ';') +1);
AnsiString Name2 = (StrRScan(List->Strings[Index2].c_str(), ';') + 1);
return AnsiCompareStr(Name1, Name2);
}
void __fastcall TFormular::Button1Click(TObject *Sender)
{
TStringList *sList = new TStringList;
try
{
sList->AddStrings(Memo1->Lines);
sList->CustomSort(SortCallback);
Memo1->Lines->Assign(sList);
}
__finally{delete sList;}
}
/**********************************************************/
 
 

Re:BCB3 missing implementation of: TStringList -> CustomSort( )

"Oren (Halvani.de)" < XXXX@XXXXX.COM >wrote in message
Quote
the problem is, that I use BCB 3 Pro. and there isn't an
implementation
of ->CustomSort( )
can someone tell me if there is an implementation of CustomSort ( )
or maybe
something
similar to it for BCB 3 ???
Before you do anything else, make sure that the *sort keys* in your
multiple-part strings are all the same length. If you are depending
on an alpha collation order sort, you may be disappointed in the
result on different-length strings from AnsiCompareStr(Name1, Name2),
especially if any numbers are involved.
I still have BCB3 on one machine, and I don't think there's an answer
to your question.
If you must avoid writing a sort, you could put the various strings
into a TListView as Items and sub-items, and use the CustomSort method
of TListView. Large listview's are slow, as are large TStringLists...
If I were in your situation, I would assign the input TStringList to a
temporary TStringList, and do a simple, first-degree selection sort on
the appropriate substring, producing a list of Strings[] indexes.
Then I would Add each string to the original, emptied TStringList and
delete the temporary. Yes, this is slow for a large list, but there's
no alternative in the model you present!
If raw speed were the issue, you'd move everything to a
two-dimensional c arrary and use quicksort(). That's not so fast
either. And one point of keeping it all VCL is to trade speed for
maintainability.
 

Re:BCB3 missing implementation of: TStringList -> CustomSort( )

"Timothy H. Buchman" <tbuchmanREMOVE(at)PLEASEcitycenter D O To r g>
wrote in message news:3fa8988b$ XXXX@XXXXX.COM ...
Quote
"Oren (Halvani.de)" < XXXX@XXXXX.COM >wrote in message
news:3fa70417$ XXXX@XXXXX.COM ...
I had one more idea. It's *not* faster or "better", but it avoids
writing a sort, which I get the feeling you'd like to do. I did this
once in BCB3 to sort a TStringGrid on a chosen column. It depends on
my assumption that you are happy with an alpha sort of the n'th string
in your composite strings. First, re-read this paragraph of mine:
Quote
Before you do anything else, make sure that the *sort keys* in your
multiple-part strings are all the same length. If you are depending
on an alpha collation order sort, you may be disappointed in the
result on different-length strings from AnsiCompareStr(Name1,
Name2),
especially if any numbers are involved.
(You may be able to fix this by left-padding with blanks.)
Extract the sort key strings from the input array and put (*only*)
them in a new TStringList, whose Sorted property is true. When you
put them in, use the AddObject method, and store the subscript of the
composite string's position in the original array as the TObject.
When you're done, the sorted TStringList Objects tell you how to Add()
each original composite string, one at a time, to a new TStringList
that will hold those (complete) strings in the sorted order. (Or, as
I mentioned, you could first Assign the original strings to a
temporary TStringList, Clear() the origininal, and put the sorted
strings back there in the right order.
There's a normal amount of VCL overhead here, but it's clear that's
not your primary concern.
T.H.B.
 

{smallsort}

Re:BCB3 missing implementation of: TStringList -> CustomSort( )

"Oren (Halvani.de)" < XXXX@XXXXX.COM >wrote in message
Quote
the problem is, that I use BCB 3 Pro
From now on, can you please specify that when you post? That is a very
important detail that people need to know when answering questions.
Quote
and there isn't an implementation of ->CustomSort( )
Correct. CustomSort() was not introduced into TStringList until BCB5.
Quote
can someone tell me if there is an implementation of CustomSort ( )
There is not.
Quote
or maybe something similar to it for BCB 3 ???
There is nothing native for what you ask. You'll just have to sort the list
manually.
Gambit