Larry Griffiths
2008-06-15 21:18:30 UTC
I have been meaning to report this as a possible bug for quite some time but
never got around to it.
I wrote a compare procedure for the TList Sort method.
This procedure gets called with the same pointers for the first and second
parameters ( p1 and p2 ).
I think this is a bug in the sort. ( why call MyCompare when both pointers
are the same? )
I am using BDS2007 but I think it is also present in BDS2006 and BCB5.
Here is the code:
TStringList* SL;
//---------------------------------------------------------------------------
int __fastcall MyCompare( void* p1, void* p2)
{
int a = (int) p1;
int b = (int) p2;
if( SL->Strings[a] > SL->Strings[b] ) return 1;
if( SL->Strings[a] < SL->Strings[b] ) return -1;
return 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TList* List = new TList;
SL = new TStringList;
for( int ix = 0; ix < 5; ix++ )
{
List->Add( (void*) ix );
}
SL->Add( "Z" );
SL->Add( "A" );
SL->Add( "S" );
SL->Add( "C" );
SL->Add( "B" );
List->Sort( &MyCompare );
Memo1->Clear();
for( int ix = 0; ix < 5; ix++ )
{
Memo1->Lines->Add( SL->Strings[(int)List->Items[ix]] );
}
delete List;
delete SL;
}
never got around to it.
I wrote a compare procedure for the TList Sort method.
This procedure gets called with the same pointers for the first and second
parameters ( p1 and p2 ).
I think this is a bug in the sort. ( why call MyCompare when both pointers
are the same? )
I am using BDS2007 but I think it is also present in BDS2006 and BCB5.
Here is the code:
TStringList* SL;
//---------------------------------------------------------------------------
int __fastcall MyCompare( void* p1, void* p2)
{
int a = (int) p1;
int b = (int) p2;
if( SL->Strings[a] > SL->Strings[b] ) return 1;
if( SL->Strings[a] < SL->Strings[b] ) return -1;
return 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TList* List = new TList;
SL = new TStringList;
for( int ix = 0; ix < 5; ix++ )
{
List->Add( (void*) ix );
}
SL->Add( "Z" );
SL->Add( "A" );
SL->Add( "S" );
SL->Add( "C" );
SL->Add( "B" );
List->Sort( &MyCompare );
Memo1->Clear();
for( int ix = 0; ix < 5; ix++ )
{
Memo1->Lines->Add( SL->Strings[(int)List->Items[ix]] );
}
delete List;
delete SL;
}