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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:44:14+00:00 2026-05-25T21:44:14+00:00

for write something in a file i use for example this code: procedure MyProc

  • 0

for write something in a file i use for example this code:

procedure MyProc (... );
const
  BufSize = 65535;
var
  FileSrc, FileDst: TFileStream;
  StreamRead: Cardinal;
  InBuf, OutBuf: Array [0..bufsize] of byte;
begin
  .....
  FileSrc := TFileStream.Create (uFileSrc, fmOpenRead Or fmShareDenyWrite);
  try
    FileDst := TFileStream.Create (uFileTmp, fmCreate);
    try
      StreamRead := 0;
      while ((iCounter < iFileSize) or (StreamRead = Cardinal(BufSize))) 
      begin
        StreamRead := FileSrc.Read (InBuf, BufSize);
        Inc (iCounter, StreamRead);
      end;
    finally
      FileDst.Free;
    end;
  finally
    FileSrc.Free;
  end;
end;

And for I/O file i use a array of byte, and so is all ok, but when i use a string, for example declaring:

InBuf, OutBuf: string  // in delphi xe2 = unicode string

then not work. In sense that file not write nothing. I have understood why, or just think to have understood it.
I think that problem maybe is why string contain just a pointer to memory and not static structure; correct?
In this case, there is some solution for solve it? In sense, is possible to do something for i can to write a file using string and not vector? Or i need necessary use a vector?
If possible, can i can to do ?
Thanks very much.

  • 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-25T21:44:15+00:00Added an answer on May 25, 2026 at 9:44 pm

    There are two issues with using strings. First of all you want to use RawByteString so that you ensure the use of byte sized character elements – a Unicode string has elements that are two bytes wide. And secondly you need to dereference the string which is really just a pointer.

    But I wonder why you would prefer strings to the stack allocated byte array.

    procedure MyProc (... );
    const
      BufSize = 65536;
    var
      FileSrc, FileDst: TFileStream;
      StreamRead: Cardinal;
      InBuf: RawByteString;
    begin
      .....
      FileSrc := TFileStream.Create (uFileSrc, fmOpenRead Or fmShareDenyWrite);
      try
        FileDst := TFileStream.Create (uFileTmp, fmCreate);
        try
          SetLength(InBuf, BufSize);
          StreamRead := 0;
          while ((iCounter < iFileSize) or (StreamRead = Cardinal(BufSize))) 
          begin
            StreamRead := FileSrc.Read (InBuf[1], BufSize);
            Inc (iCounter, StreamRead);
          end;
        finally
          FileDst.Free;
        end;
      finally
        FileSrc.Free;
      end;
    end;
    

    Note: Your previous code declared a buffer of 65536 bytes, but you only ever used 65535 of them. Probably not what you intended.

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

Sidebar

Related Questions

Sometimes, I want to use an ObjectOutputStream to write something to a file or
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
I'd like to write a plugin that does something with the currently edited file
so I have an external javascript file, lets call it something.js and i document.write
I write something similar to the following code a lot. It basically toggles an
I have to write something in vbscript that need to use a unique set.
Let me explain by an example. In Delphi, you can write procedure TForm1.FormKeyPress(Sender: TObject;
Lets say i have this code: use strict; use LWP qw ( get );
I want to write something that acts just like confirm() in javascript, but I
I'm trying to write something that puts the contents of the message on a

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.