Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Need a little help with Delphi to C++ conversion

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3331

PostPosted: Sat Feb 23, 2013 12:13 am    Post subject: Need a little help with Delphi to C++ conversion Reply with quote

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
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Feb 23, 2013 7:58 am    Post subject: Reply with quote

Post whole pascal code.
_________________
Back to top
View user's profile Send private message MSN Messenger
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3331

PostPosted: Sat Feb 23, 2013 9:06 am    Post subject: Reply with quote

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
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Feb 23, 2013 9:26 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3331

PostPosted: Wed Feb 27, 2013 10:19 pm    Post subject: Reply with quote

Worked, thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites