Re: [fpc-pascal] Adding a array of float in ressource and use it ?
Define "much less success". How are you writing the array and how are you reading it? Hello and thanks for answer. Here how the array is written: var buffer : array of float; FileBuffer.Data := TFileStream.Create(filename,fmCreate); FileBuffer.Data.Seek(0, soFromBeginning); FileBuffer.Data.WriteBuffer(buffer[0],Length(Buffer)); The result is OK if integer 16/32 bit inside the buffer. If data inside the buffer is float 32 bit, result is a file of... 2 octets... Thanks. 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-tp5727765p572.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
On Mon, 6 Mar 2017, fredvs wrote: Define "much less success". How are you writing the array and how are you reading it? Hello and thanks for answer. Here how the array is written: var buffer : array of float; FileBuffer.Data := TFileStream.Create(filename,fmCreate); FileBuffer.Data.Seek(0, soFromBeginning); FileBuffer.Data.WriteBuffer(buffer[0],Length(Buffer)); The result is OK if integer 16/32 bit inside the buffer. If data inside the buffer is float 32 bit, result is a file of... 2 octets... You must write FileBuffer.Data.WriteBuffer(buffer[0],Length(Buffer)*Sizeof(Float)); Because for a dynamic array, length returns the length in elements, not in bytes. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Incomplete code example in FPC docs
Hi, http://www.freepascal.org/docs-html/rtl/typinfo/ispublishedprop.html According to the above URL, that code example is not compilable as-is, because TMyTestObject is not defined anywhere. Shouldn't the code examples in the documentation be compilable as-is? ie: allow the developer to copy and paste the code in a empty file, then compile and run to try it out? Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
Hello Michael and thanks for answer. >You must write > FileBuffer.Data.WriteBuffer(buffer[0],Length(Buffer)*Sizeof(Float)); Ha, perfect, many thanks. But there is something that I do not catch, why is it working for integer ? Sizeof Integer is 2 bits so, normally: FileBuffer.Data.WriteBuffer(buffer[0],Length(Buffer)); should not work (but it works) ---> Length(Buffer) = 1/2 * Length(Buffer)*Sizeof(integer) ? 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-tp5727765p5727780.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
On Mon, 6 Mar 2017, fredvs wrote: Hello Michael and thanks for answer. You must write FileBuffer.Data.WriteBuffer(buffer[0],Length(Buffer)*Sizeof(Float)); Ha, perfect, many thanks. But there is something that I do not catch, why is it working for integer ? Sizeof Integer is 2 bits so, normally: FileBuffer.Data.WriteBuffer(buffer[0],Length(Buffer)); should not work (but it works) ---> Length(Buffer) = 1/2 * Length(Buffer)*Sizeof(integer) I don't know. By all logic, it should not work either. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
> I don't know. By all logic, it should not work either. Yes, it is I think too. Some more explanation: I use a "global" buffer of float to store data. Those data can be int16, int32 or float32. For example, If data are integer (16 or 32 bit), I do: bufferfloat[x] := 127.0 ; (for int16) bufferfloat[x] := 2147483646.0; (for int32) If data are float 32 bit, I do: bufferfloat[x] := 0.2147483646 ; (for float32) So it seems to me Sizeof(bufferfloat[x]) is the same in the 3 cases (alway sizeof(float)). Aaargh, sorry, I always come with extreme programming (or extreme dummy) question. 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-tp5727765p5727782.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
Am 06.03.2017 13:42 schrieb "fredvs" : > > > I don't know. By all logic, it should not work either. > > Yes, it is I think too. > > Some more explanation: > > I use a "global" buffer of float to store data. > Those data can be int16, int32 or float32. > > For example, > > If data are integer (16 or 32 bit), I do: > > bufferfloat[x] := 127.0 ; (for int16) > > bufferfloat[x] := 2147483646.0; (for int32) > > If data are float 32 bit, I do: > > bufferfloat[x] := 0.2147483646 ; (for float32) > > So it seems to me Sizeof(bufferfloat[x]) is the same in the 3 cases (alway > sizeof(float)). Of course it's always the same size as it's an array of cfloat after all and no assignment will change that. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
> 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 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@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
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@lists.freepascal.org > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
On Mon, 6 Mar 2017, 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 If the bufferfloat is the same variable in all cases, there should be no difference whatsoever. The write operation doesn't care a fig about the actual contents of the buffer. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
On Mon, 6 Mar 2017, Lukasz Sokol wrote: 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 There should be absolutely no need for that ? Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
Or, quite comically maybe: use a text file... write/writeln and read/readln, and use zip compression on the text file to compress data... -L. On 06/03/17 15:59, Lukasz Sokol wrote: > 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@lists.freepascal.org >> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal >> > > > ___ fpc-pascal maillist > - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
> 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 ? 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-tp5727765p5727789.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
> I don't know what you're doing wrong, but the following works: Huh, it is exactly what I (think to) do. And re-reading hundred times my code does not see any difference. OK, I will re-read thousand times the code, maybe I will find what is wrong. Many thanks for your code Sven. 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-tp5727765p5727791.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
Am 06.03.2017 22:45 schrieb "fredvs" : > > > I don't know what you're doing wrong, but the following works: > > Huh, it is exactly what I (think to) do. > And re-reading hundred times my code does not see any difference. > > OK, I will re-read thousand times the code, maybe I will find what is wrong. Then try to minimize your code as much as possible and then show it here (an as small as possible compileable example that shows your problem). Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding a array of float in ressource and use it ?
Re-hello. Ok, I do not find yet the guilty in my code, I will re-try a other day. By the way, your code is working perfectly Sven. Now, last part of the question: how to convert that file stored into ressource but without to write to the disk (only memory stream)? A TFileStream could be used but it needs a path. And in ressource there is no path to use in TFileStream.Create('/the/path/filename', fmOpenRead); What could be the solution ? 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-tp5727765p5727793.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal