Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reading in a file of bytes.

Posted on 1998-06-25
6
Medium Priority
?
173 Views
Last Modified: 2010-04-04
I am trying to find a way of reading a file of bytes straight into a structure. Currently i have it reading in one byte at a time into an array and it is much too slow! I am using Delphi 3 if this makes any difference :)
0
Comment
Question by:pootlecat
[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
  • 3
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
BlackMan earned 400 total points
ID: 1355636
One (fast) method is using BlockRead procedure. This allows you to specify how many bytes you want to read at a time.
There is a good example in the Helpfile.
0
 
LVL 3

Expert Comment

by:vladika
ID: 1355637
Use TFileStream and its methods Read, Write, ReadBuffer, WriteBuffer

for Example

procedure Example;
type TMyStructure = record
   T1, T2, T3: Word;
  end;
var MyStructure: TMyStructure;
    FileStream: TFileStream;
begin
  FileStream := TFileStream.Create('c:\temp\myfile.dat', fmOpenRead);
  try
    while FileStream.Position < FileStream.Size do { while not end of file }
    begin
      FileStream.ReadBuffer(MyStructure, SizeOf(TMyStructure)); { read MyStructure }
      { process MyStructure }
    end;
  finally
    FileStream.Free;
  end;
end;

0
 

Author Comment

by:pootlecat
ID: 1355638
Thanks for the example :) It's working great!
The help files on this version are a terrible mess and i couldn't find an example there.
0
Independent Software Vendors: 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!

 

Author Comment

by:pootlecat
ID: 1355639
Thanks for the example :) It's working great!
The help files on this version are a terrible mess and i couldn't find an example there.
0
 
LVL 3

Expert Comment

by:vladika
ID: 1355640
Where is my points for example? :)
0
 

Author Comment

by:pootlecat
ID: 1355641
Um tricky - you can have some points with pleasure but how do i do that lol?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

715 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