Solved

Move a string to a TStringStream and vice-versa

Posted on 2013-05-10
3
1,207 Views
Last Modified: 2013-05-17
What is the correct way to move the content of a string to a TStringStream and vice-versa
Also, I suppose that the string should not a declared unicode but ... ?
Thanks
0
Comment
Question by:LeTay
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39155187
you can use it both ways:
- at create:    
  strm := TStringStream.Create(sText_var);
- at later time:
  strm := TStringStream.Create('');
  strm.WriteString(sText_var);

read:
  strm.Position := 0;
  sResult := strm.ReadString(strm.Size);
0
 

Author Comment

by:LeTay
ID: 39156170
Many thanks for your quick answer, sinisav
It is "normal" that the string (sResult in your example) is unicode ?
Unicode means a even number of bytes so what happens if the stream contains an odd number of bytes ?
Thanks
0
 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 39156992
As far I can see (in source :-) it is irrelevant what type of string is. Internally all goes with byte operation. If you put unicode string then you must read as unicode, same with ansistring. What version of Delphi you have? In newer Delphi (XEx) there is Encoding property which tells you what type of string is on, or when you before you write to stream set this prop. to right value.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now