Solved

Reading in a file of bytes.

Posted on 1998-06-25
6
167 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

8 Experts available now in Live!

Get 1:1 Help Now