Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4260964
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:59:26+00:00 2026-05-21T05:59:26+00:00

I am trying to learn Free Pascal using Lazarus and one of my pet

  • 0

I am trying to learn Free Pascal using Lazarus and one of my pet projects involves reading the 64 byte headers of a particular set of untyped files that cannot be read and displayed using text or ASCII related procedures (so cannot be outputted directly to Memo boxes etc).

So far, I have devised the following code which does, I think, read in the 64 bytes of the header and I am using TStreams and a “Select Directory” dialog box to do this, based on advice received via the Lazarus IRC. My question though is how to actually USE the data that is read into the buffer from the header? For example, in the headers, there are sequences of 8 bytes, then 16 bytes, then 2 bytes and so on that I want to “work on” to generate other output that will eventually be converted to a string to go into my string grid.

Some of what I have so far is based on what I found here written by Mason Wheeler near the end (http://stackoverflow.com/questions/455790/fast-read-write-from-file-in-delphi) but it only shows how to read it in, not how to use it. I also read this (http://stackoverflow.com/questions/4309739/best-way-to-read-parse-a-untyped-binary-file-in-delphi) but again, it shows you how to READ the data too, but not subsequently USE the data. Any guidance wamrly received! So far, the code below just outputs single value integer numbers to the edit box, as opposed to, say, a range of 8 hexadecimal values.

PS – I am new to programming so please be gentle! Nothing too complex.

procedure TForm1.ProbeFile(FileIterator: TFileIterator);

type
 TMyHeader = Array[1..64] of packed record
 First8Bytes,
 Next16Bytes,
 Next2Bytes: byte;
 end;

var

  FI : TFileIterator;                      //File Iterator class
  SG : TStringGrid;
  NumRead : SmallInt;
  FileToProbe: TStream;
  header: TMyHeader;

begin
  FI := TFileIterator.Create;
  SG := TStringGrid.Create(self);


  // Open the file and read the header
  FileToProbe := TFileStream.Create(FileIterator.FileName, fmOpenRead);
  try
    FileToProbe.seek(0, soFromBeginning);
    FileToProbe.ReadBuffer(header, SizeOf(header));
    edit1.text := IntToStr(header[0].First8Bytes);  // Just outputs '0' to the field?  If I try '10' it ooutputs '29' and so on
  finally
    FileToProbe.Free;
  end; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:59:27+00:00Added an answer on May 21, 2026 at 5:59 am

    Please forgive me if I misunderstood your question.

    As I understand it there is a header of 64 bytes. The first 8 bytes belong together, then the next 16 bytes and finally another 2 bytes.

    To me it seems the declaration for this header should be:

       TMyHeader = packed record
         First8Bytes: array[0..7] of byte;  
         Next16Bytes: array [0..15] of byte;
         Next2Bytes: array [0..1] of byte;
         // add more if you like
       end;
    

    This recordtype has a size of 8+16+2 = 26 bytes.

    Your code that reads the header looks ok to me, So I won’t repeat that.

    The next16bytes in your header can be retrieved, for example, like this:

    edit1.text:= '';
    // needs a declaration of a variable "i" as integer
    for i:= 0 to 15 do
      edit1.text:= edit1.text + IntToStr(header.next16bytes[i]) + '-';
    

    Change the value of the first byte in the next2bytes part of your header as follows (again as an example):

    header.next2bytes[0]:= 123;
    

    Finally, you could write your changes back to the header of the file with help of the filetoprobe.writebuffer method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to learn about php's arrays today. I have a set of arrays like
I have been trying to learn Scala in my free time and learn to
I'm trying to learn more about malloc & free, so I've created a dylib
I am trying to setup and learn the Fat Free Framework for PHP. http://fatfree.sourceforge.net/
I am trying to learn to free pointer in a vector, I have read
I am trying to learn XML by reading from W3schools. I am already at
I am trying to learn the basics of socket programming and am using some
Trying to learn how to use Data.Binary and hit a roadblock here: http://www.haskell.org/haskellwiki/Serialisation_and_compression_with_Data_Binary D:\Projects\haskell\serialize\ex1.hs:114:26:
I'm trying learn more about RavenDB and at the moment to focus on how
I am trying learn the use of lambda expressions and hence still struggling to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.