Solved

Reading in a file of bytes.

Posted on 1998-06-25
6
171 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 100 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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 285
Delphi 2 92
tvirtualstringtree freeze when load too manny images 10 94
Breakpoint doesn't stop in my variable 3 48
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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