Solved

Reading in a file of bytes.

Posted on 1998-06-25
6
169 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 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 100
Delphi XE10, MySQL Query 4 143
Best Firemonkey component pack 1 101
how to change, disabled button color FMX ? 1 32
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now