954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ to Delphi conversion

I am trying to convert a piece of code into Delphi but fall down when it comes to this example :

void __stdcall GetBuffers( short **xBuffers, unsigned long nValues)
{
.......
memcpy(TargetA, xBuffers[0], nValues * sizeof(short));
memcpy(TargetB, xBuffers[1], nValues * sizeof(short));
memcpy(TargetC, xBuffers[3], nValues * sizeof(short));
memcpy(Targetd, xBuffers[4], nValues * sizeof(short));
}

Could you please help

MorrisL
Newbie Poster
3 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

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! }

cao
Newbie Poster
12 posts since Oct 2009
Reputation Points: 11
Solved Threads: 5
 

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]

MorrisL
Newbie Poster
3 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

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:

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:

a: array of array of short;


And in the code, to set the lengths:

SetLength(a, 10); //10 pointers to arrays of shorts;
for i:= Low(a) to High(a) do
  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.

BitFarmer
Junior Poster in Training
51 posts since Nov 2009
Reputation Points: 12
Solved Threads: 5
 

The use of a: array of array worked a treat. Thank you.

MorrisL
Newbie Poster
3 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

int main()
{
string strtext("khiro delphi");
int iLength = strtext.length();
for (int i=0;i<=iLength;i++)
{ if (!(strtext[i]==' '))
{
cout<

khiro.alg
Newbie Poster
1 post since May 2010
Reputation Points: 10
Solved Threads: 0
 

Hi Khiro, you post a piece of code but don't ask anything at all... so?

BitFarmer
Junior Poster in Training
51 posts since Nov 2009
Reputation Points: 12
Solved Threads: 5
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You