Board index » cppbuilder » AArgh...How do I use TStringListSortCompare???

AArgh...How do I use TStringListSortCompare???


2005-07-29 11:50:52 PM
cppbuilder51
This should be so simple, but I cannot figure it out.
My source file contains:
TStringList *data=new TStringList;
...
data->CustomSort(CardSort);
...
//----------------------------------
int __fastcall TForm1::CardSort(TStringList *List,
int Index1, int Index2)
{
...
}
My Header file contains:
private: // User declarations
int __fastcall CardSort(TStringList *List,
int Index1, int Index2);
I'm getting error E2034
Cannot convert 'int (_fastcall * (_closure )(TStringList
*,int,int))(TStringList *,int,int)' to 'int (_fastcall
*)(TStringList *,int,int)'
from the compiler. The help (both online and written) is no help.
What is declared incorrectly and how should it be declared???
TIA,
 
 

Re:AArgh...How do I use TStringListSortCompare???

Hi Brian,
The callback function that's passed to the CustomSort() method cannot
be a non-static member function of a class. Just make it a standalone
function (not a member of the TForm1 class)...
int __fastcall CardSort(TStringList *List,
int Index1, int Index2)
{
}
HTH,
C++Builder Developer's Journal
bcbjournal.com
BCB Commonly Asked Questions
bcbjournal.com/bcbcaq
Brian wrote:
Quote
I'm getting error E2034
Cannot convert 'int (_fastcall * (_closure )(TStringList
*,int,int))(TStringList *,int,int)' to 'int (_fastcall
*)(TStringList *,int,int)'
 

Re:AArgh...How do I use TStringListSortCompare???

"Brian" < XXXX@XXXXX.COM >writes:
Quote
I'm getting error E2034
Cannot convert 'int (_fastcall * (_closure )(TStringList
*,int,int))(TStringList *,int,int)' to 'int (_fastcall
*)(TStringList *,int,int)'
When dealing with "function pointer" related errors, if you see
_closure in the message think "member function", and if it's not
there, think "freestanding (nonmember) function".
Keeping that in mind should help you interpret the error message a
little better in the future too.
--
Chris (TeamB);
 

{smallsort}

Re:AArgh...How do I use TStringListSortCompare???

Chris Uzdavinis (TeamB) < XXXX@XXXXX.COM >wrote:
Quote
When dealing with "function pointer" related errors, if you see
_closure in the message think "member function", and if it's not
there, think "freestanding (nonmember) function".

Keeping that in mind should help you interpret the error message a
little better in the future too.

--
Chris (TeamB);
Sheesh...that was easy. Thanks much!!