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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:04:02+00:00 2026-06-13T20:04:02+00:00

When I try to pass tmemorystream as a var or pointer to a procedure

  • 0

When I try to pass tmemorystream as a var or pointer to a procedure it comes back corrupted. What is the proper way to do this?

For example:

function tform1.downloadmemupdate(url, desc: string; var data: tmemorystream; var msg: string): boolean;
begin
  filelabel.Caption:=desc;
  downloadmemthread:=tdownloadmemthread.create(url);
  dlcancelbtn.Enabled:=true;
  downloadmemthread.dlstart;
  waitforsingleobject(downloadmemthread.Handle, INFINITE);

  downloadmemthread.data.SaveToStream(data); //corrupted
  downloadmemthread.data.SaveToFile('data.zip');  //works

  dlcancelbtn.Enabled:=false;
  result:=not (downloadmemthread.canceled and downloadmemthread.success);
  dlcanceled:=downloadmemthread.canceled;
  msg:=downloadmemthread.msg;
  downloadthread.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-06-13T20:04:03+00:00Added an answer on June 13, 2026 at 8:04 pm

    You don’t create data within this method. As it is a var (byref) parameter, I would expect it to be created within tform1.downloadmemupdate, i.e.:

    data := TMemoryStream.Create;
    

    Note that if you create an object like this, you will need to free it somewhere else, probably in the calling code.

    e.g.

       Data := nil;
       try
         downloadmemupdate(url, desc, data, msg);
         // do something with data
       finally
         Data.Free;
       end;  
    

    An alternative (and the idiomatic method in Delphi) is to pass objects by value (without the var). and leave it to the calling code to create and destroy them. This is mainly because Delphi doesn’t have garbage collection, so it forces the person writing the calling code to think about “ownership”.

    This would be

    function tform1.downloadmemupdate(url, desc: string; data: TStream; var msg: string): boolean;
    begin
      filelabel.Caption:=desc;
      downloadmemthread:=tdownloadmemthread.create(url);
      try
        ...
        downloadmemthread.data.SaveToStream(data); //corrupted
        downloadmemthread.data.SaveToFile('data.zip');  //works    
      finally
        downloadmemthread.Free;
      end;
    
    end;
    

    calling code:

       Data := TMemoryStream.Create;
       try
         downloadmemupdate(url, desc, data, msg);
         // do something with data
       finally
         Data.Free;
       end;  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am calling this function: val(array[i][index]) when i try to pass a time stamp
I try to pass a pointer of a structure which is given me as
Whenever I try to pass a variable through url with the l() function like:
In the following program I try to pass a structure to a function. But
I'm getting this error when I try to pass a task to a Celery
My RESTful interface works fine until I try to pass a WHERE statement Example:
I try to pass a bundle between two activities. This bundle contains a Serializable
When I try to pass a string to a function like so i=file:///bla/bla/bla; Fade(i);
I try to pass array using jquery by ajax and back but my code
when I try to pass this value, I get this error 09 is not

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.