We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Reading in a file of bytes.

pootlecat
pootlecat asked
on
Medium Priority
186 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 :)
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
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;

Author

Commented:
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.

Author

Commented:
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.

Commented:
Where is my points for example? :)

Author

Commented:
Um tricky - you can have some points with pleasure but how do i do that lol?
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.