Am 30.07.2017 08:21 schrieb "Bo Berglund" <bo.bergl...@gmail.com>:
> 3) Change the BlockWrite command from
> BlockWrite(F, Buffer[1], Length(Buffer));
> to
> BlockWrite(F, Buffer, Length(Buffer));
>
> Note that I would like to *not* specify the index of the first element
> of the array so that the same code can work for both cases depending
> on conditional setting.
> But I am worried that Buffer will reference a different memory
> location than Buffer[0].
>
> So are these two calls equivalent when Buffer is an AnsiString or a
> TBytes array:
> BlockWrite(F, Buffer[0], Length(Buffer));
> BlockWrite(F, Buffer, Length(Buffer));

Like with String you need to reference the first element with dynamic
arrays, in this case Buffer[0], otherwise you'll write the management
record and following unrelated data.
You can either use "Low(buffer)" as the index which *should* work with
strings as well, though I don't know whether it always did... If that
doesn't work simply write two overloaded inline functions that return the
index of the first element depending on whether it's String or TBytes.

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to