C++ to Delphi conversion

Thread Solved

Join Date: Nov 2009
Posts: 3
Reputation: MorrisL is an unknown quantity at this point 
Solved Threads: 0
MorrisL MorrisL is offline Offline
Newbie Poster

C++ to Delphi conversion

 
0
  #1
Nov 13th, 2009
I am trying to convert a piece of code into Delphi but fall down when it comes to this example :
Pascal and Delphi Syntax (Toggle Plain Text)
  1. void __stdcall GetBuffers( short **xBuffers, unsigned long nValues)
  2. {
  3. .......
  4. memcpy(TargetA, xBuffers[0], nValues * sizeof(short));
  5. memcpy(TargetB, xBuffers[1], nValues * sizeof(short));
  6. memcpy(TargetC, xBuffers[3], nValues * sizeof(short));
  7. memcpy(Targetd, xBuffers[4], nValues * sizeof(short));
  8. }
Could you please help
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 10
Reputation: cao is an unknown quantity at this point 
Solved Threads: 4
cao cao is offline Offline
Newbie Poster
 
0
  #2
Nov 13th, 2009
MemCpy (Destination, Source, Num)
destination - Pointer to the destination array where the content is to be copied
source - Pointer to the source of data to be copied
num - Number of bytes to copy.

Delphi
procedure Move(const Source; var Dest; Count: Integer);

Move(Source, Destination, SizeOf(Destinaton)); { SizeOf = safety! }
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: MorrisL is an unknown quantity at this point 
Solved Threads: 0
MorrisL MorrisL is offline Offline
Newbie Poster

Clarification

 
0
  #3
Nov 13th, 2009
I am sorry for not being clear. It is not the moving that I have a problem with but the de-referencing of **xBuffers to xBuffers[0] to xBuffers[3]
Last edited by MorrisL; Nov 13th, 2009 at 10:15 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 41
Reputation: BitFarmer is an unknown quantity at this point 
Solved Threads: 5
BitFarmer BitFarmer is offline Offline
Light Poster
 
0
  #4
Nov 17th, 2009
If I am right, **ptr is a pointer to an array of pointers to short integers... in delphi it is not used like this (thanks, Lord!).

If you know the lengths of the arrays when coding:

Pascal and Delphi Syntax (Toggle Plain Text)
  1. var a: array[0..10, 0..20] of short;

Then you pass a as paramter, and use a[0] as the first pointer, a[1]... etc.

If the lengths are not know (as i suppose), you just make this:

Pascal and Delphi Syntax (Toggle Plain Text)
  1. a: array of array of short;

And in the code, to set the lengths:

Pascal and Delphi Syntax (Toggle Plain Text)
  1. SetLength(a, 10); //10 pointers to arrays of shorts;
  2. for i:= Low(a) to High(a) do
  3. SetLength(a[i], 20); //Each one with 20 elements (could be different for each array)

So you don't need to play with pointers of pointer to pointer that point to shorts or any other tipycal C puzzles, just pass an "a" and it is done.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: MorrisL is an unknown quantity at this point 
Solved Threads: 0
MorrisL MorrisL is offline Offline
Newbie Poster
 
0
  #5
Nov 19th, 2009
The use of a: array of array worked a treat. Thank you.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum


Views: 1124 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC