| View previous topic :: View next topic |
| Author |
Message |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3331
|
Posted: Sat Feb 23, 2013 12:13 am Post subject: Need a little help with Delphi to C++ conversion |
|
|
Hi all,
How do I convert this Pascal code to C++?
In specific, the 'function (...)' part;.
| Code: | procedure TItems.Sort(Compare: TItemSortCompare);
begin
if (List<>nil) and (Count>1) then
QSort(List, 0, Count-1,
function(Item1, Item2: Pointer): Integer
begin
Result := Compare(Item1, Item2);
end);
|
This is how far I got, but the compiler won't eat it:
| Code: | void __fastcall TItems::Sort(TItemSortComparator fCompare)
{
if (List!=NULL && Count>1)
QSort(List, 0, iCount-1,
int __fastcall (TItemPointer *Item1, TItemPointer* Item2)
{
return fCompare(Item1, Item2);
}
} |
Thanks!
|
|
| Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sat Feb 23, 2013 7:58 am Post subject: |
|
|
Post whole pascal code.
_________________
|
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3331
|
Posted: Sat Feb 23, 2013 9:06 am Post subject: |
|
|
It's not my code, so I'd rather not. But, that's the whole procedure, I just missed the last "end;" from it.
All I need to know is how the QSort call would be done in C++.
Thanks!
|
|
| Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sat Feb 23, 2013 9:26 am Post subject: |
|
|
remove that __fastcall
or something like this:
| Code: | int (__fastcall *pfComparator)(TItemPointer*, TItemPointer*);
int __fastcall comparator(TItemPointer* Item1, TItemPointer* Item1)
{
return fCompare(Item1, Item2);
}
void __fastcall TItems::Sort(TItemSortComparator fCompare)
{
if (List!=NULL && Count>1)
{
pfComparator = &comparator;
QSort(List, 0, iCount-1, pfComparator);
}
} |
_________________
|
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3331
|
Posted: Wed Feb 27, 2013 10:19 pm Post subject: |
|
|
| Worked, thanks!
|
|
| Back to top |
|
 |
|