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

Recommended Answers

All 6 Replies

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

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]

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]==' '))
        {
          cout<<strtext[i];
        }
  else 
cout<<endl; 
       }
return 0;
 }

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.