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

8 Years
Discussion Span
Last Post by BitFarmer

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.

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

Move(Source, Destination, SizeOf(Destinaton)); { SizeOf = safety! }


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]

Edited by MorrisL: n/a


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.


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

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

Edited by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.