473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Delphi Blockread in C#

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
Nov 17 '05 #1
3 4201
Hi Tomas,

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

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"Tomas Jönsson" <to***********@not.specified.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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

Nov 17 '05 #2
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

"Tomas Jönsson" <to***********@not.specified.com> escribió en el mensaje
news:%2***************@TK2MSFTNGP10.phx.gbl...
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

Nov 17 '05 #3
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
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Erva | last post by:
Hi, Is there someone who has moved from Delphi to VS.NET? I'am using Delphi currently but seriously considering to moving VS.NET. I would like to hear if someone has already done that, is it...
10
by: Arda Han | last post by:
I am migrating my some applications from Delphi to C#. But... Yes But I don't know C# professionally. I am using DLL in delphi like this : ..... const RFID_103_485IO = 'Cihaz.dll'; ...
9
by: Gclinton | last post by:
I'm looking for a comparsion of C# to Delphi .net. My company is about to begin the process of reengineering a Delphi tightly coupled win32 app and a Older Java webclient that uses JSP over to an...
3
by: lukeharpin | last post by:
Currently I have been developing applications in Delphi 7. Recently I meet up with a friend of mine who previously developed in Delphi, from version 1 - 7. When Delphi 8 .net was release he found...
7
by: Sanjay Kedare | last post by:
Hi, I am evaluating various alternatives of converting Delphi (Ver 4.0) screens to C# screens. Are there any tools available for such conversion? if yes how much conversion do they achieve? The...
13
by: lukeharpin | last post by:
Hi World, We have been developing Engineering software in Delphi 3,4,5,6,7 for a few years now. This morning we had a discussion about OOP and re-programming the software to which the question...
1
by: Thomas Due | last post by:
Hi, I manage an rather old application in which we have some fairly complex (ugly) Delphi code. This is Delphi 6 we're talking about. Among all this Delphi code there is method for formating a...
4
by: =?Utf-8?B?ZGF2ZWJ5dGhlc2Vh?= | last post by:
Dear List, We have a large application written in Delphi. I am writing a mobile app written in .NET (C#) which reads and writes into the Delphi applications Oracle database via a .NET Web...
11
by: gnuist006 | last post by:
Is there a Delphi equivalent in the C world or Scheme/LISP world ? Recently, Delphi is in resurgence. In Russia people are using like crazy. For example, Bolega has written a free image...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.