Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Share:
Notifications
Clear all

[Solved] Lazarus Pascal / Delphi - How to Copy a TMemoryStream into a String

4 Posts
2 Users
3 Reactions
2,968 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2869
Topic starter  

A quick trick, showing you how to copy the content of a TMemoryStream into a string:

function MemoryStreamToString(aMemoryStream: TMemoryStream): AnsiString;
begin
SetString(Result, PAnsiChar(aMemoryStream.Memory), aMemoryStream.Size);
end;

 


   
shonty reacted
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Hello.

How to copy from TMemoryStream to Clipboard as string ?

Thanks!

This post was modified 3 months ago by Anonymous

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2869
Topic starter  

Hi Shonty,

I'm not the most experienced TMemoryStream user, but it sounds like this example could be helpful.
It seems to show to copy the content of a TMemoryStream as a TStringList to a TMemo.

The TStringList.text then can be copied to the clipboard with (obviously, 

var
  List : TStringList;

...
Clipboard.AsText := List.Text; (TStringList)
...

Hope this is helpful.


   
shonty reacted
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Yes, thanks. I didn't get any results with TMemoryStream either.
I replaced it with TStringStream.

Thanks.


   
Hans reacted
ReplyQuote
Share: