[Lazarus] Passing an array to a function
Dave Coventry
dgcoventry at gmail.com
Mon Jan 19 16:35:47 CET 2009
Hi Andy, thanks for the response.
The array was declared as
var fsbuffer: array of Byte;
I tried your suggestion and typed the array as
Type TByteBuffer=Array of Byte;
then declared the buffer
var fsbuffer: TByteBuffer;
I also declared the function using 'var' as you suggested
function FieldValueAsString(var fsbuffer: TByteBuffer; fitype,fisize:
integer): string;
But my app is still falling over at the same point.
2009/1/19 Andrew Brunner <andrew.t.brunner at gmail.com>:
> Hi Dave,
>
>
> My first comment would be you must declare the input as a variable.
> Next, I probably would type the Array out as well before using it.
>
> Type TByteBuffer=Array of Byte;
>
> function FieldValueAsString(var fsbuffer:TByteBuffer; fitype,fisize:
> integer): string;
>
> Byte arrays should not generate an error. There may be a memory leak
> for instances where you pass them in as constant values. Because the
> Memory manager would need to free that memory as it is a dynamic
> array.
>
> -Andy
>
>
> On Mon, Jan 19, 2009 at 8:20 AM, Dave Coventry <dgcoventry at gmail.com> wrote:
>> I have a function that I'm trying to pass an array to.
>>
>> function FieldValueAsString(fsbuffer: array of Byte; fitype,fisize:
>> integer): string;
>>
>> Calling the function:
>>
>> setlength(fsbuffer,recordsize);
>> FS:=TFileStream.Create(fname, fmshareDenyWrite);
>> FS.Seek(seekpos,soFromBeginning);
>> FS.ReadBuffer(fsbuffer,recordsize);
>> dfstring:= FieldValueAsString(fsbuffer,fitype,fisize);
>>
>> Generates the error "Project raised exception class SIGSEGV"
>> _______________________________________________
>> Lazarus mailing list
>> Lazarus at lazarus.freepascal.org
>> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
>>
> _______________________________________________
> Lazarus mailing list
> Lazarus at lazarus.freepascal.org
> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
>
More information about the Lazarus
mailing list