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

  • Home
  • SEARCH
  • 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 6990671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:23:11+00:00 2026-05-27T19:23:11+00:00

I am saving some custom created Objects classes (Stream data) to File. I need

  • 0

I am saving some custom created Objects classes (Stream data) to File.

I need to be able to load the contents of the File into a TStringList so I can append a new line to the end of the File, and then Save the changes.

This is not working though because LoadFromFile cannot seem to parse the File correctly. I assume because of the funny characters the Stream Saves to File as, and TStringList expects plain textual information.

How can I do the following:

  • Read any Raw Binary File into a TStringList.
  • Add my new Line, eg StringList1.Add(MyString);
  • Save the Raw Binary File again.

This question actually relates to another question I asked: Save a CRC value in a file, without altering the actual CRC Checksum?

This is what I am trying to do:

  • Calculate the CRC Checksum of my Saved Stream File.
  • Add the CRC Value to the end of the File.
  • Re-save the File.

Then when I attempt to Open my Stream File:

  • Assign the CRC Value (at the end of the File) to a variable.
  • Delete the CRC Value from the File.
  • Save the Stream File as a new Temp File.
  • Calculate and Compare the CRC of the Temp File, with the CRC stored in the variable.
  • If the CRC of the File matches the internal stored CRC Value, I can process the File as normal.

But I don’t know how to Read or Write the Raw Binary Data of the File.

I would be grateful if someone could give me some help and advice thanks 🙂

  • 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-27T19:23:12+00:00Added an answer on May 27, 2026 at 7:23 pm

    This class descends from TStringList and adds a check value at the end when writing to a file. This value is checked whenever the file is read.

    type
      TCRCStringList = class(TStringList)
      type
        TCRC = LongWord;
      private
        function CalcCRC(Stream: TStream): TCRC;
      public
        procedure LoadFromStream(Stream: TStream; Encoding: TEncoding); override;
        procedure SaveToStream(Stream: TStream; Encoding: TEncoding); override;
      end;
    
    function TCRCStringList.CalcCRC(Stream: TStream): TCRC;
    begin
      Result := 42;  // place CRC calculation here
    end;
    
    procedure TCRCStringList.LoadFromStream(Stream: TStream; Encoding: TEncoding);
    var
      crc: TCRC;
      temp: TMemoryStream;
    begin
      temp := TMemoryStream.Create;
      try
        temp.CopyFrom(Stream, Stream.Size - Sizeof(crc));
        Stream.Read(crc, Sizeof(crc));
        if crc <> CalcCRC(temp) then
          raise Exception.Create('CRC error');
        temp.Position := 0;
        inherited LoadFromStream(temp, Encoding);
      finally
        temp.Free;
      end;
    end;
    
    procedure TCRCStringList.SaveToStream(Stream: TStream; Encoding: TEncoding);
    var
      crc: TCRC;
      temp: TMemoryStream;
    begin
      temp := TMemoryStream.Create;
      try
        inherited SaveToStream(temp, Encoding);
        temp.Position := 0;
        crc := CalcCRC(temp);
        temp.Position := temp.Size;
        temp.Write(crc, Sizeof(crc));
        Stream.CopyFrom(temp, 0); // count = 0 copies the whole stream from the beginning
      finally
        temp.Free;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a web service which is saving some data into to db.
I need to write some methods for loading/saving some classes to and from a
I have a action class for saving some data to a database.In action class
I'm getting some data from the web service and saving it in the core
Using MSXML4, I am creating and saving an xml file: MSXML2::IXMLDOMDocument2Ptr m_pXmlDoc; //add some
I created a custom behavior that exposes some custom dependency properties whose values change
I created a custom AlertDialog to display a Spinner and some EditText elements. When
I need to create a custom allocator for std:: objects (particularly and initially for
any recommendations for saving four strings into an own file format that is read
I've created a custom VS template which uses an IWizard class to do some

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.