Re: [Lazarus] Unpack of PHP
2013/2/6 Marco van de Voort [...] > That's so boring! In FPC 2.7.1 this should work: > > uses >Classes, >SysUtils, >StreamEx; > var >VFile: TFileStream; > begin >VFile := TFileStream.Create('data.ascii', fmOpenRead or > fmShareDenyWrite); >try > VFile.Seek(2, 0); > WriteLn(VFile.ReadWordBE); > VFile.Seek(6, 0); > WriteLn(VFile.ReadWordBE); > finally >VFile.Free; > end; > end. > ReadWordBE is very nice. Thank you very much guy! :) -- Silvio Clécio My public projects - github.com/silvioprog -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
On Mon, Feb 04, 2013 at 03:29:54PM -0200, silvioprog wrote: > Oops... And this is the full code: > > program project1; > > {$mode objfpc}{$H+} > > uses > Classes, > SysUtils; > > function ReadInt(AStream: TStream): Word; > begin > Result := 0; > AStream.Read(Result, SizeOf(Word)); > Result := BEtoN(Result); > end; > > var > VFile: TFileStream; > begin > VFile := TFileStream.Create('data.ascii', fmOpenRead or fmShareDenyWrite); > try > VFile.Seek(2, 0); > WriteLn(ReadInt(VFile)); > VFile.Seek(6, 0); > WriteLn(ReadInt(VFile)); > finally > VFile.Free; > end; > end. That's so boring! In FPC 2.7.1 this should work: uses Classes, SysUtils, StreamEx; var VFile: TFileStream; begin VFile := TFileStream.Create('data.ascii', fmOpenRead or fmShareDenyWrite); try VFile.Seek(2, 0); WriteLn(VFile.ReadWordBE); VFile.Seek(6, 0); WriteLn(VFile.ReadWordBE); finally VFile.Free; end; end. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
2013/2/4 silvioprog > 2013/2/4 Vincent Snijders > >> 2013/2/4 silvioprog : >> > 2013/2/4 David Knaack >> >> >> >> I may not understand the scope of your question, but could you use the >> >> swap function? >> >> >> >> http://www.freepascal.org/docs-html/rtl/system/swap.html >> >> >> >> Like so (edited in email, not compile checked): >> >> >> >> function ReadMWord(AStream: TStream): Word; >> >> var >> >> MW: Word >> >> begin >> >> AStream.Read(MW, SizeOf(Word)); >> >> Result := Swap(MW); >> >> end; >> > >> > >> > Perfect! :) >> > >> > Thank you very much! >> >> Instead of swap, you may use beton, so that it works on big endian cpus >> too: >> http://www.freepascal.org/docs-html/rtl/system/beton.html >> >> Vincent >> > > Many thanks guy, worked like a charm too! :) I'll use BEtoN instead Swap. > Oops... And this is the full code: program project1; {$mode objfpc}{$H+} uses Classes, SysUtils; function ReadInt(AStream: TStream): Word; begin Result := 0; AStream.Read(Result, SizeOf(Word)); Result := BEtoN(Result); end; var VFile: TFileStream; begin VFile := TFileStream.Create('data.ascii', fmOpenRead or fmShareDenyWrite); try VFile.Seek(2, 0); WriteLn(ReadInt(VFile)); VFile.Seek(6, 0); WriteLn(ReadInt(VFile)); finally VFile.Free; end; end. -- Silvio Clécio My public projects - github.com/silvioprog -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
2013/2/4 Vincent Snijders > 2013/2/4 silvioprog : > > 2013/2/4 David Knaack > >> > >> I may not understand the scope of your question, but could you use the > >> swap function? > >> > >> http://www.freepascal.org/docs-html/rtl/system/swap.html > >> > >> Like so (edited in email, not compile checked): > >> > >> function ReadMWord(AStream: TStream): Word; > >> var > >> MW: Word > >> begin > >> AStream.Read(MW, SizeOf(Word)); > >> Result := Swap(MW); > >> end; > > > > > > Perfect! :) > > > > Thank you very much! > > Instead of swap, you may use beton, so that it works on big endian cpus > too: > http://www.freepascal.org/docs-html/rtl/system/beton.html > > Vincent > Many thanks guy, worked like a charm too! :) I'll use BEtoN instead Swap. -- Silvio Clécio My public projects - github.com/silvioprog -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
2013/2/4 silvioprog : > 2013/2/4 David Knaack >> >> I may not understand the scope of your question, but could you use the >> swap function? >> >> http://www.freepascal.org/docs-html/rtl/system/swap.html >> >> Like so (edited in email, not compile checked): >> >> function ReadMWord(AStream: TStream): Word; >> var >> MW: Word >> begin >> AStream.Read(MW, SizeOf(Word)); >> Result := Swap(MW); >> end; > > > Perfect! :) > > Thank you very much! Instead of swap, you may use beton, so that it works on big endian cpus too: http://www.freepascal.org/docs-html/rtl/system/beton.html Vincent -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
2013/2/4 David Knaack > I may not understand the scope of your question, but could you use the > swap function? > > http://www.freepascal.org/docs-html/rtl/system/swap.html > > Like so (edited in email, not compile checked): > > function ReadMWord(AStream: TStream): Word; > var > MW: Word > begin > AStream.Read(MW, SizeOf(Word)); > Result := Swap(MW); > end; > Perfect! :) Thank you very much! -- Silvio Clécio My public projects - github.com/silvioprog -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
I may not understand the scope of your question, but could you use the swap function? http://www.freepascal.org/docs-html/rtl/system/swap.html Like so (edited in email, not compile checked): function ReadMWord(AStream: TStream): Word; var MW: Word begin AStream.Read(MW, SizeOf(Word)); Result := Swap(MW); end; On Mon, Feb 4, 2013 at 9:13 AM, silvioprog wrote: > 2013/2/4 silvioprog > >> 2013/2/4 leledumbo >> >>> > ps. I tried the Unpack function of FPC, but I don't know how to use it. >>> >>> Unpack() is for unpacking previously Pack()-ed data >>> >> >> So, I'm trying to improve the PowerPDF to support PNG images, but I dont >> know how to convert ASCII to Integer. >> > > Solved: > > function ReadMWord(AStream: TStream): Word; > type > TMotorolaWord = record > case Byte of > 0: (Value: Word); > 1: (Byte1, Byte2: Byte); > end; > var > MW: TMotorolaWord; > begin > AStream.Read(MW.Byte2, SizeOf(Byte)); > AStream.Read(MW.Byte1, SizeOf(Byte)); > Result := MW.Value; > end; > > :) > > -- > Silvio Clécio > My public projects - github.com/silvioprog > > -- > ___ > Lazarus mailing list > Lazarus@lists.lazarus.freepascal.org > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > > -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
2013/2/4 silvioprog > 2013/2/4 leledumbo > >> > ps. I tried the Unpack function of FPC, but I don't know how to use it. >> >> Unpack() is for unpacking previously Pack()-ed data >> > > So, I'm trying to improve the PowerPDF to support PNG images, but I dont > know how to convert ASCII to Integer. > Solved: function ReadMWord(AStream: TStream): Word; type TMotorolaWord = record case Byte of 0: (Value: Word); 1: (Byte1, Byte2: Byte); end; var MW: TMotorolaWord; begin AStream.Read(MW.Byte2, SizeOf(Byte)); AStream.Read(MW.Byte1, SizeOf(Byte)); Result := MW.Value; end; :) -- Silvio Clécio My public projects - github.com/silvioprog -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
2013/2/4 silvioprog > ... but I dont know how to convert ASCII to Integer. > ... to convert ASCII pack to Integer. -- Silvio Clécio My public projects - github.com/silvioprog -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
2013/2/4 leledumbo > > ps. I tried the Unpack function of FPC, but I don't know how to use it. > > Unpack() is for unpacking previously Pack()-ed data > So, I'm trying to improve the PowerPDF to support PNG images, but I dont know how to convert ASCII to Integer. -- Silvio Clécio My public projects - github.com/silvioprog -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
2013/2/4 ik > On Mon, Feb 4, 2013 at 1:34 PM, silvioprog wrote: > > Hello, > > > > In FPC, I'm trying to load a ASCII content and onvert it to integer, but, > > without success. In PHP I do it easily. > > > > I send two files in attached: > > > > 1. php - demo in PHP working fine (the demo uses unpack function: > > http://www.php.net/manual/en/function.unpack.php); > > 2. fpc - demo in FPC partially implemented; > > > > So, how to do it in FPC? > > Take a look at my fp-msgpack[1] (I need to rewrite it, because the way > that array and maps works), but it does exactly what pack and upack > does. > > > > > Thank you! > > > > ps. I tried the Unpack function of FPC, but I don't know how to use it. > > > > -- > > Silvio Clécio > > My public projects - github.com/silvioprog > > [1] https://github.com/ik5/fp-msgpack > I have not found the line that does the conversion (from ASCII to integer). The your code is big. I will need to study it to understand it. In PHP was so easy (only two lines), that I would have swore that something native and easy to use with Free Pascal. Thank you! -- Silvio Clécio My public projects - github.com/silvioprog -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
> ps. I tried the Unpack function of FPC, but I don't know how to use it. Unpack() is for unpacking previously Pack()-ed data -- View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Unpack-of-PHP-tp4029070p4029074.html Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Unpack of PHP
On Mon, Feb 4, 2013 at 1:34 PM, silvioprog wrote: > Hello, > > In FPC, I'm trying to load a ASCII content and onvert it to integer, but, > without success. In PHP I do it easily. > > I send two files in attached: > > 1. php - demo in PHP working fine (the demo uses unpack function: > http://www.php.net/manual/en/function.unpack.php); > 2. fpc - demo in FPC partially implemented; > > So, how to do it in FPC? Take a look at my fp-msgpack[1] (I need to rewrite it, because the way that array and maps works), but it does exactly what pack and upack does. > > Thank you! > > ps. I tried the Unpack function of FPC, but I don't know how to use it. > > -- > Silvio Clécio > My public projects - github.com/silvioprog [1] https://github.com/ik5/fp-msgpack > > -- > ___ > Lazarus mailing list > Lazarus@lists.lazarus.freepascal.org > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus