[Lazarus] Passing a section of an array to a function.

Dave Coventry dgcoventry at gmail.com
Mon Sep 10 11:22:14 CEST 2012


On 10 September 2012 10:14, Sven Barth <pascaldragon at googlemail.com> wrote:
> Did you really write "&"? The address operator is "@", but this won't make
> your code work anyway. If you did indeed write "&" (which is for escaping
> keywords) you do indeed only pass the 32nd element to your function.

:blush:

I did indeed. That would explain it!

> Dynamic arrays are internally pointers to an array (more or less). So if you
> would use "@buf[32]" you would be passing the address of one element to a
> function that takes an array. If you know the amount of bytes you want to
> copy then you should use "Copy(buf, 32, count)" as argument for decompress_r
> or if you don't know the amount you should change your function from "array
> of Byte" to "PByte" and pass the address of the 32nd byte using "@buf[32]".
> The remaining part of the function can stay the same.

Thank you, Sven, that will help a lot.

Many thanks,

Dave




More information about the Lazarus mailing list