[fpc-pascal] Adding a array of float in ressource and use it ?
Sven Barth
pascaldragon at googlemail.com
Mon Mar 6 20:37:27 CET 2017
On 06.03.2017 19:31, fredvs wrote:
>> Or, quite comically maybe: use a text file
>
> Or maybe, like in my second post, convert float32 ---> integer32
>
> for x := 0 to length(floatbuffer) -1 do
> begin
> floatbuffer[x] := round(floatbuffer[x] * 2147483647);
> if floatbuffer[x] > 2147483647 then floatbuffer[x] := 2147483647;
> if floatbuffer[x] < -2147483647 then floatbuffer[x] := -2147483647;
> end;
>
> And do the reverse when reading from the file ?
I don't know what you're doing wrong, but the following works:
=== code begin ===
program tfloatbuf;
{$mode objfpc}
uses
SysUtils, Classes, ctypes;
var
fbuf: array of cfloat;
i: LongInt;
fs: TFileStream;
begin
SetLength(fbuf, 42);
for i := Low(fbuf) to High(fbuf) do
fbuf[i] := 3.1415;
Writeln('Writing data to ', ParamStr(1));
fs := TFileStream.Create(ParamStr(1), fmOpenWrite or fmCreate);
try
fs.WriteBuffer(fbuf[0], Length(fbuf) * SizeOf(fbuf[0]));
finally
fs.Free;
end;
SetLength(fbuf, 0);
SetLength(fbuf, 42);
Writeln('Reading data from ', ParamStr(1));
fs := TFileStream.Create(ParamStr(1), fmOpenRead);
try
fs.ReadBuffer(fbuf[0], Length(fbuf) * SizeOf(fbuf[0]));
finally
fs.Free;
end;
for i := Low(fbuf) to High(fbuf) do
Writeln(fbuf[i]);
end.
=== code end ===
Regards,
Sven
More information about the fpc-pascal
mailing list