Delphi/Lazarus: Write Stream to Stream
Question by Guest | Last update on 2024-01-23 | Created on 2014-12-15
I would like to write the content of a stream into another stream.
For example, the content of some TFileStream into an arbitrary TMemoryStream.
How can I achieve this?
Related Topics
Delphi/Lazarus: How to set up a Link to a Website in an Application
Tutorial | 0 Comments
Delphi/Lazarus: Command Line Parameter Tutorial Part 1: Sending
Tutorial | 0 Comments
Delphi: Global Treatment of Errors (Exceptions)
Tutorial | 0 Comments
Delphi/Lazarus: 3 Ways to round a Number to X Decimal Places
Tutorial | 7 Comments
Delphi: Multiline Caption for TLabel (at Run Time and Design Time)
Tutorial | 1 Comment
Lazarus: Load File as Byte Array and save Byte Array as File
Tutorial | 0 Comments
Delphi/Lazarus: Delete selected Items from ListBox using DEL-Key
Tip | 3 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
Assuming having two streams, StreamA and StreamB, you can copy the content from StreamB into StreamA using the following code:
It is important to set the position to 0 first. Otherwise (if the current stream position is not 0) it will not be copied from the beginning of the stream (except, of course, you only want to copy a part of the stream beginning somewhere in the middle).
The second parameter of CopyFrom is the length that should be copied. With passing "StreamB.Size", the full length of the stream is copied, with values smaller than the size of the stream, it is possible to copy only a part of the stream.
Last update on 2024-01-23 | Created on 2014-12-17