 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
JRB Guest
|
Posted: Fri Jan 19, 2007 11:24 pm Post subject: Question re: Retrieving and manipulating data from binary fi |
|
|
I need to iterate through a binary file and come up w/ output. I'm using an export tool that exports the data into XML (which I can then use), but I want to read the original file so I can skip having to export the XML and then read that file into my program.
I have the structure of the file, and can read the appropriate data, but for two values, I can't for the life of me figure out how to retrieve the data correctly.
The structure is something like (I believe it's C):
unsigned int locx;
unsigned int locy;
double address;
char char1;
time_t filedate;
char zeros[19];
I've translated this into a structure in Delphi as follows:
sLocX : single;
sLocY : single;
dAddress : double;
cChar : array [0..1] of byte;
dFileDate : TDateTime;
cChar2 : array [0..19] of byte;
I can iterate through the file and populate sLocX, sLocY, dAddress, dFileDate (cChar and cChar2 aren't used). dAddress and dFileDate are used as is, but I need to do some further calculations to sLocX and sLocY.
How can I separate into distinct variables the sLocX and sLocY values so that the first two bytes are stored in sLocX1, the second two in sLocX2, the third in sLocX3 and the last two in sLocX4? Is this possible or do I need to change the type when retrieving data? (I know I need to read sLocX and sLocY as 4 bytes from the file b/c whenever I change this value, the resulting dAddress and FileDate end up being incorrect.)
Whenever I try and read directly to the sLocX1..4 by calling
binStream.Read(sLocX1, 1)
...
binStream.Read(sLocX4, 1)
I get a bad result. (I will know whether the result is bad by feeding the values into an equation and seeing what the answer is -- I have the desired outcome for each record from what's in the XML file.)
I've been working on the this for the past week or so and it's driving me mad. Any suggestions on how to accomplish this would be greatly appreciated. |
|
| Back to top |
|
 |
JRB Guest
|
Posted: Sat Jan 20, 2007 12:03 am Post subject: FORMATTED Question re: Retrieving and manipulating data from |
|
|
"JRB" <jrb (AT) email (DOT) com> wrote:
| Quote: |
I need to iterate through a binary file and come up w/ output.
I'm using an export tool that exports the data into XML (which
I can then use), but I want to read the original file so I can
skip having to export the XML and then read that file into my
program.
I have the structure of the file, and can read the appropriate
data, but for two values, I can't for the life of me figure out
how to retrieve the data correctly.
The structure is something like (I believe it's C):
unsigned int locx;
unsigned int locy;
double address;
char char1;
time_t filedate;
char zeros[19];
I've translated this into a structure in Delphi as follows:
sLocX : single;
sLocY : single;
dAddress : double;
cChar : array [0..1] of byte;
dFileDate : TDateTime;
cChar2 : array [0..19] of byte;
I can iterate through the file and populate sLocX, sLocY,
dAddress, dFileDate (cChar and cChar2 aren't used). dAddress
and dFileDate are used as is, but I need to do some further
calculations to sLocX and sLocY.
How can I separate into distinct variables the sLocX and sLocY
values so that the first two bytes are stored in sLocX1, the
second two in sLocX2, the third in sLocX3 and the last two in
sLocX4? Is this possible or do I need to change the type when
retrieving data? (I know I need to read sLocX and sLocY as 4
bytes from the file b/c whenever I change this value, the
resulting dAddress and FileDate end up being incorrect.)
Whenever I try and read directly to the sLocX1..4 by calling
binStream.Read(sLocX1, 1)
..
binStream.Read(sLocX4, 1)
I get a bad result. (I will know whether the result is bad by
feeding the values into an equation and seeing what the answer
is -- I have the desired outcome for each record from what's in
the XML file.)
I've been working on the this for the past week or so and it's
driving me mad. Any suggestions on how to accomplish this
would be greatly appreciated. |
|
|
| Back to top |
|
 |
Iain Macmillan Guest
|
Posted: Thu Jan 25, 2007 8:07 am Post subject: Re: Question re: Retrieving and manipulating data from binar |
|
|
In article <45b0fed0$1 (AT) newsgroups (DOT) borland.com>, "JRB" <jrb (AT) email (DOT) com> wrote:
| Quote: | The structure is something like (I believe it's C):
Yes it is C.
unsigned int locx;
unsigned int locy;
double address;
char char1;
time_t filedate;
char zeros[19];
I've translated this into a structure in Delphi as follows:
sLocX : single;
sLocY : single;
Bad translation: an unsigned int is definitely not a single! |
Cardinal might do, but if the values never exceed 2 billion integer would do
just as well and if the values do exceed 2 billion DWord is the only option.
| Quote: | dAddress : double;
cChar : array [0..1] of byte;
why has this array appeared? ..Its just a char.
dFileDate : TDateTime;
cChar2 : array [0..19] of byte;
nearly but not quite: |
char zeros[19] means an array of 19 chars. If the numbering starts at zero
the 19th one is zeros[18]
so array [0..18] of byte;
| Quote: |
I can iterate through the file and populate sLocX, sLocY, dAddress,
dFileDate (cChar and cChar2 aren't used). dAddress and dFileDate are used
as is, but I need to do some further calculations to sLocX and sLocY.
How can I separate into distinct variables the sLocX and sLocY values so
that the first two bytes are stored in sLocX1, the second two in sLocX2,
the third in sLocX3 and the last two in sLocX4? Is this possible or do I
need to change the type when retrieving data?
|
Its probably best to retrieve the data according to the file specification
and then manipulate it to your own needs.
var slocx1,slocx2: integer;
slocx1:=slocx and $FFFF;
slocx2:=slocx shr 8;
- is one possible way of doing the manipulation you ask for. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|