Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-25 Thread Paul Nicholls
- Original Message - From: "M Pulis" To: "FPC-Pascal users discussions" Sent: Monday, October 26, 2009 9:27 AM Subject: Re: [fpc-pascal] WORD (2 bytes) to String conversion On Oct 25, 2009, at 3:09 PM, Paul Nicholls wrote: - Original Message - From

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-25 Thread M Pulis
On Oct 25, 2009, at 3:09 PM, Paul Nicholls wrote: - Original Message - From: "Graeme Geldenhuys" > To: "FPC-Pascal users discussions" Sent: Friday, October 23, 2009 11:10 PM Subject: [fpc-pascal] WORD (2 bytes) to String conversion Hi, I'm reading in a

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-25 Thread Paul Nicholls
- Original Message - From: "Graeme Geldenhuys" To: "FPC-Pascal users discussions" Sent: Friday, October 23, 2009 11:10 PM Subject: [fpc-pascal] WORD (2 bytes) to String conversion Hi, I'm reading in a WORD (2 bytes) from a binary file. I can display the

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-24 Thread Marco van de Voort
In our previous episode, J??rgen Hestermann said: > > As Marco suggested... Char size might not always be the same. > > Why that? I hope noone changes the meaning of such long-time types some > day. If a new type is needed, then it should get a new name too. Codegear did this with Delphi 2009 i

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-24 Thread Jürgen Hestermann
As Marco suggested... Char size might not always be the same. Why that? I hope noone changes the meaning of such long-time types some day. If a new type is needed, then it should get a new name too. ___ fpc-pascal maillist - fpc-pascal@lists.freep

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-24 Thread Vincent Snijders
Graeme Geldenhuys schreef: 2009/10/24 Vincent Snijders : But then you still cannot do: if header.id='HS' then // magic is correct. That is why I proposed a static array of char. No, but I can do this... which is sufficient. var s: string begin s := hdr^.ID; if S = "HS" then ...

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-24 Thread Graeme Geldenhuys
2009/10/24 Vincent Snijders : > > But then you still cannot do: > > if header.id='HS' then >  // magic is correct. > > That is why I proposed a static array of char. No, but I can do this... which is sufficient. var s: string begin s := hdr^.ID; if S = "HS" then ... -- Regards, -

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-24 Thread Vincent Snijders
Graeme Geldenhuys schreef: On 23/10/2009, Vincent Snijders wrote: You can consider declaring the ID in the header record type as array[1..2] of char. As Marco suggested... Char size might not always be the same. I did however change my header to array[0..1] of byte instead. But then you

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
On 23/10/2009, Marco van de Voort wrote: > > > > You can consider declaring the ID in the header record type as > > array[1..2] of char. > > (starting to use ansichar might not be bad) Good point. But I preferred to go with array of Byte. -- Regards, - Graeme - _

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
On 23/10/2009, Vincent Snijders wrote: > > You can consider declaring the ID in the header record type as array[1..2] > of char. As Marco suggested... Char size might not always be the same. I did however change my header to array[0..1] of byte instead. -- Regards, - Graeme - ___

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Marco van de Voort
In our previous episode, Vincent Snijders said: > > various bits of information, without the need for a hex editor etc... > > So the solution described earlier will suffice for my needs. > > > > > > You can consider declaring the ID in the header record type as > array[1..2] of char. (starting

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Vincent Snijders
Graeme Geldenhuys schreef: On 23/10/2009, Jürgen Hestermann wrote: Wouldn't it be more direct to use Blockwrite(,header.ID,sizeof(header.ID)); I read the complete header structure in one go (155 bytes). I simply want to output to a text file, a human readable structure of the complete INF f

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
On 23/10/2009, Jürgen Hestermann wrote: > > Wouldn't it be more direct to use > Blockwrite(,header.ID,sizeof(header.ID)); I read the complete header structure in one go (155 bytes). I simply want to output to a text file, a human readable structure of the complete INF file. The INF file format

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Jürgen Hestermann
I would like my program to output the following: - Header Section header.ID(5348h = "HS") ... - Wouldn't it be more direct to use Blockwrite(,header.ID,sizeof(header.ID)); That would make it robust against changes of ID size and would avoid the many typ

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
On 23/10/2009, Jeff Wormsley wrote: > Oh, I was fairly certain of that. Its just these little routines tend to > end up in libraries of handy code. I tend to be overly cautious with some > of these because of that. Point taken. :-) This code is purposely rewritten and totally standalone so I

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Jeff Wormsley
Graeme Geldenhuys wrote: On 23/10/2009, Jeff Wormsley wrote: That's dangerous, though, if your magic number's two bytes aren't printable That should never be a problem for my tool though. The tool I am writing is specific to the INF help format. The tool dumps the fil

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
On 23/10/2009, Jeff Wormsley wrote: > > That's dangerous, though, if your magic number's two bytes aren't printable That should never be a problem for my tool though. The tool I am writing is specific to the INF help format. The tool dumps the file structure to a text file. (I need this for debu

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Jeff Wormsley
Graeme Geldenhuys wrote: Hi, I'm reading in a WORD (2 bytes) from a binary file. I can display the Hex format of that value without a problem, but I would also like to display the String value of that WORD variable. It's the first 2 bytes of a file, which contains the "magic number" of the file

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
2009/10/23 Aleksa Todorovic : > > w: WORD > ... > YourString := Chr(Lo(w)) + Chr(Hi(w)) > or > YourString := Chr(Hi(w)) + Chr(Lo(w)) Ah, thanks. I was close, I used High() and Low() instead. :-( Dope! -- Regards, - Graeme - ___ fpGUI - a cross-p

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Aleksa Todorovic
On Fri, Oct 23, 2009 at 14:10, Graeme Geldenhuys wrote: > Hi, > > I'm reading in a WORD (2 bytes) from a binary file. I can display the > Hex format of that value without a problem, but I would also like to > display the String value of that WORD variable. It's the first 2 bytes > of a file, which

[fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
Hi, I'm reading in a WORD (2 bytes) from a binary file. I can display the Hex format of that value without a problem, but I would also like to display the String value of that WORD variable. It's the first 2 bytes of a file, which contains the "magic number" of the file. I would like my program t