Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Reading in a file of bytes.

Posted on 1998-06-25
6
Medium Priority
?
175 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
  • 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
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!

 

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

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…
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…
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…
Screencast - Getting to Know the Pipeline
Suggested Courses

885 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