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 6540201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:56:59+00:00 2026-05-25T10:56:59+00:00

I am working with Delphi Prism and creating and writing into binary file using

  • 0

I am working with Delphi Prism and creating and writing into binary file using BinaryWriter as follows.

method TUnit.Write(bw:BinaryWriter);
var
    i:Integer;
begin
    bw.write(ord(uType));
    bw.Write(ord(State));
    bw.Write(Address);
    bw.Write(SubAddress);

    for i:=1 to 20 do
        bw.Write(fDefs[i]);
end;

My question to you is this. Does the write method write line per line or bytes after bytes or character after character without line feed or carriage return?

The reason I am asking this question is because I am confused when it comes to writing and reading string without specific numbers of characters like array of characters.

For instance:

method WritetoFile;
var
    x:integer;
    thestr:string;
begin
    BinaryWriter thefile := new BinaryWriter(File.Create("test.dat"));
    thefile.write(thestr);
    thefile.write(x);
    thefile.Close;
end;

method ReadFromFile;
var
   x:integer;
   thestr:string;
begin
   BinaryReader thefile := new BinaryReader(File.OpenRead("test.dat"));
   thestr:=thefile.ReadString;
   x:=thefile.ReadInt32;
   thefile.Close;
end;

That’s how I wrote my program and it seems to work fine, but as I said I am confused.

How does it know how many bytes or characters length to read or write when it is a string data type without giving it a specific numbers of length to read?

  • 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-25T10:56:59+00:00Added an answer on May 25, 2026 at 10:56 am

    Does BinaryWriter “Write method” work the same as Writeln method from Delphi?

    No it does not.

    How does it know how many bytes or characters length to read or write when it is a string data type without giving it a specific numbers of length to read?

    In many ways you don’t really need to know how BinaryWriter and BinaryReader does it. You are using it correctly. You just need to pair each Write() call with a matching ReadXXX() call of the appropriate type.

    The documentation does describe the underlying binary file format. You don’t need to write or read the length of the string since the Binary I/O classes do exactly that on your behalf.

    A length-prefixed string represents the string length by prefixing to the string a single byte or word that contains the length of that string. This method first writes the length of the string as a UTF-7 encoded unsigned integer, and then writes that many characters to the stream by using the BinaryWriter instance’s current encoding.

    So you can safely write a string which contains linefeeds and when it is read those linefeeds will be preserved.

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

Sidebar

Related Questions

Working on a console application using Delphi 7, and have run into a problem.
I'm working in Delphi 2007. Net, where I can find an example of using
I am currently working with Delphi Prism for Mono development. So, the software can
im working on a project using delphi 7 , The project is a maintenance
I am using Delphi 2007 and working on some presentation software. The current module
I am working with Delphi Prism for .NET. I need to call a public
I am working with Delphi Prism for .NET. I need to be able to
im working on delphi 7 , and i have an applicaton where im using
im working on an application using delphi 6 , where im trying to integrate
I followed these instructions while trying to get remote debugging working with Delphi 2007.

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.