[fpc-pascal] Adding a array of float in ressource and use it ?
Lukasz Sokol
el.es.cr at gmail.com
Tue Mar 7 14:55:21 CET 2017
Hi,
On 07/03/17 13:23, Michael Van Canneyt wrote:
>
>> Huh? Of course you can do that rather similary in C as well.
>
> Indeed. You can do exactly the same. You can do this:
>
> {$mode objfpc}
> uses classes;
>
>
> Type
> Float = Double;
> TFloatArray = Array of Float;
>
> Procedure TestRW(X : TFloatArray);
>
> Var
> F : TFileStream;
> Y : TFloatArray;
> I : Integer;
>
> begin
> // Write
> F:=TFileStream.Create('float.dat',fmCreate);
> try
so here is what I am seeing in Fre;D's code, that he managed to paste in one of the previous
messages :
// "FileBuffer.Data.Seek(0, soFromBeginning);"
F.Seek(0, soFromBeginning); /// this it would be in Michaels' code
I don't think it matters if you newly create the stream...
looks like something (probably) performed by the constructor already;
(just a stab in the dark here, unless we take the time to look into Fred's github ?)
-L.
> F.WriteBuffer(X[0],Length(X)*SizeOf(Float));
> finally
> F.Free;
> end;
> // Read
> F:=TFileStream.Create('float.dat',fmOpenRead);
> try
> SetLength(Y,F.Size div SizeOf(Float));
> F.ReadBuffer(Y[0],F.Size);
> finally
> F.Free;
> end;
> // Check
> If Length(Y)<>Length(X) then
> Writeln('Wrong length')
> else For I:=0 to Length(X)-1 do
> if (X[i]<>Y[i]) then
> Writeln('Wrong element at pos ',i,': ',X[i]<>Y[i]);
> end;
>
> var
> X : TFloatArray;
> I : Integer;
>
> begin
> SetLength(X,10);
> Writeln('Floats');
> For I:=0 to Length(X)-1 do
> X[i]:=10+(1/(1+I));
> TestRW(X);
> Writeln('integers');
> For I:=0 to Length(X)-1 do
> X[i]:=10+I;
> TestRW(X);
> end.
>
> Michael.
More information about the fpc-pascal
mailing list