[Lazarus] Appending to a binary file
Dave Coventry
dgcoventry at gmail.com
Thu Jan 8 20:55:04 CET 2009
Bernd Mueller wrote:
> Dave Coventry wrote:
>
>> I have a file into which I want to put a long integer:
>>
>> 00 00 19 7A
>>
>> The file expects the value in the form:
>>
>> buffer[0]:=122;
>> buffer[1]:=25;
>> buffer[2]:=0;
>> buffer[3]:=0;
>>
>> I am then intending to write this buffer to the file
>>
>> FS.Writebuffer(buffer,4);
>>
>> Is there a way of loading the buffer directly before writing?
>>
>
> You could use the Absolute directive to map a longint variable to your
> buffer. Not pretty, but fast ;-)
>
> procedure LoadBuffer;
> var
> Buffer: Array[0..127] of Byte;
> l: Longint Absolute Buffer;
> begin
> l:= 6522;
> end;
>
Or you can use pointer operation. Someting like
type
PLongint = ^Longint;
PLongint(@Buffer[0])^ = 6522;
But be aware: Neither this nor Bernd's way are portable. The order of
byte will depend on the architecture your application runs on.
More information about the Lazarus
mailing list