Solved

Move a string to a TStringStream and vice-versa

Posted on 2013-05-10
3
1,137 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 25

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 25

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

16 Experts available now in Live!

Get 1:1 Help Now