Delphi Blockread in C#

  • Thread starter Thread starter Tomas Jönsson
  • Start date Start date
T

Tomas Jönsson

I'm trying to translate at short code snippet Delphi code to C#. Something
that shouldn't be to hard, but I directly turned into a problem that
probably is very simple. Here's the code that I'm wondering about


dbl : double;
....
BlockRead( TheFile, dbl, sizeof(dbl) );
....

All I want to read is a double from a binary file. In C# I wrote:
FileStream fs = new FileStream( fullName, FileMode.Open, FileAccess.Read );
BinaryReader r = new BinaryReader(fs);
....
double dbl = r.ReadDouble();

The value I get from doing this is not what I suspect at all. I've
discovered that reading string need to be done through a UTF7Encoder to work
correctly. My problem might have to to with sometinhg similar here, but how?
( I think I'm sure that I am at the right position before the reading.)

Any ideas would be appriciated!

Thanks/
Tomas
 
Hi Tomas,

Depends on how the double was written to the file.
Since you are mentioning UTF7Encoder, is your double written as text?
 
Tomas,

I believe that if you are positioned at the same place in the file, you
should read the same value in both programs. Delphi and C# (.NET) both use
IEEE 754 to represent floating point values. The encoding should have no
influence in this case.

Can you post the sequences of BYTES both programs read from that position?
(16 bytes should be enough)

Regards - Octavio
 
Oh dear, I wrote "I think I'm sure that I am at the right position before
the reading".
I wasn't!

I apologize for taking your time! Thank you both for answering!

:-}

/Tomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top