?
Solved

Read/write binary files

Posted on 1997-03-29
3
Medium Priority
?
194 Views
Last Modified: 2010-04-06
I'm trying to read the contents of a binary file into an array of records. e.g
 FileRead(FileHandle, TeamRecord[i], SizeOf(TeamRecord[i]));

The first field of the record is a string[25], and for some reason, the first letter of the string is not being read into the record. I'm new to Delphi - have I done something wrong??
0
Comment
Question by:ChrisGin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 150 total points
ID: 1335057
This is probably because the string in the file is 0-terminated.

A pascal string stores the length of the string in the first character of the string, and then the actual data. (Not true for the D2 type STRING without any length specifier)

'ABC' pascal string :  #3 #65 #66 #67
'ABC' 0-terminated  :  #65 #66 #67 #0

What you should do, is to declare the TeamRecord type something like this:

type
  TTeamRecord =
    AString   : ARRAY [0..24] OF CHAR;
    .
    .

Or, maybe its ARRAY [0..25], depends on the binary file format.


If this didn't solve it, leave me a comment along with your record declarations and a bit more source code.

Regards,

Erik.


0
 

Author Comment

by:ChrisGin
ID: 1335058
Thanks! That solved the problem. However, by making it an array of characters, will this mean that I can no longer perform string operations on that field? If that's true, is there a conversion function I can use to convert an array of characters to a string?
0
 
LVL 3

Expert Comment

by:sperling
ID: 1335059
Yep.

StrPas(a) returns a string, if 'a' is either a PChar or a 0-terminated array of char

Regards,

Erik.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question