[fpc-pascal] Adding a array of float in ressource and use it ?

Lukasz Sokol el.es.cr at gmail.com
Mon Mar 6 16:59:43 CET 2017


On 06/03/17 14:50, fredvs wrote:
>> I don't know. By all logic, it should not work either.
> 
> OK, It comes from a "lucky" bug (thanks to reveal it).
> There was a setlength(buffer, length(buffer) * channels) not needed.
> 
> Ok, fixed.
> 
> But the problem remain:
> 
> If data are int16 or int32: OK, the file is created with +- 1 mega bytes and
> I can get those data back.
> 
> But if data are float32: NOT OK, the file is created but with only 6 octets
> ;-( . 
> 
> For example, 
> 
> for x :=0 to length(bufferfloat) -1 do 
> bufferfloat[x] := 127 ; // for int16 ---> it works
> 
> for x :=0 to length(bufferfloat) -1 do 
> bufferfloat[x] := 2147483646;  // for int32 ---> it works
> 
> for x :=0 to length(bufferfloat) -1 do 
> bufferfloat[x] := 0.2147483646 ; // for float32 ----> it does not work  
> 

Looks like for float you'd need a conversion record

{enable packed records}

TFloatToBuffer = packed record
  case boolean of
    true: FloatField : float32;
    false : BufferField : array[0..3] of byte;
  end;
end;

for x := 0 to length(bufferfloat)-1 do
  bufferfloat[x].FloatField := {float value}

// but then special handling is likely needed to concat the buffer to write to file and reading from file
// so be careful ;)


-L.
> 
> Fre;D
> 
> 
> 
> -----
> Many thanks ;-)
> --
> View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Adding-a-array-of-float-in-ressource-and-use-it-tp5727765p5727784.html
> Sent from the Free Pascal - General mailing list archive at Nabble.com.
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> 





More information about the fpc-pascal mailing list