Hello
Here is one,
<Cpp Unit>
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "cStringListCustomSort.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
int __fastcall TForm1::StringListSortCompare( TStringList* List, int Index1, int Index2 )
{
return List->Strings[Index2].AnsiCompare( List->Strings[Index1] );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//descending sort
TStringList* SL = new TStringList;
SL->Assign( Memo1->Lines );
SL->CustomSort( StringListSortCompare );
Memo1->Lines->Assign( SL );
delete SL;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
//ascending sort
TStringList* SL = new TStringList;
SL->Assign( Memo1->Lines );
SL->Sorted=true;
Memo1->Lines->Assign( SL );
delete SL;
}
//---------------------------------------------------------------------------
<Units Header>
//---------------------------------------------------------------------------
#ifndef cStringListCustomSortH
#define cStringListCustomSortH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TMemo *Memo1;
TButton *Button1;
TButton *Button2;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
private: // User declarations
static int __fastcall StringListSortCompare( TStringList* List, int
Index1, int Index2 );
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif