<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Comments for How to move a string into a TMemoryStream or TFileStream.</title>
<link rel="alternate" type="text/plain" href="http://dn.codegear.com/article/26416" title="How to move a string into a TMemoryStream or TFileStream." />
<link rel="self" type="application/atom+xml" href="http://dn.codegear.com/article/26416/feed" title="Comments for How to move a string into a TMemoryStream or TFileStream." />
<id>http://dn.codegear.com/article/26416</id>
<updated>2008-11-19T08:31:23-08:00</updated>
<entry>
<title>re: How to move a string into a TMemoryStream or TFileStream.</title>
<author>
<name>Hendra  Suryadarma</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=27587</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=27587</id>
<updated>2001-01-16T17:01:54-08:00</updated>
<published>2001-01-16T17:01:54-08:00</published>
<summary>re: How to move a string into a TMemoryStream or TFileStream.</summary>
<content>The length of a string is needed to know how much we must allocate a string size .... Thanks for the discussion guys ... And special thanks for the program you made Ralph Friedman ... </content>
</entry>
<entry>
<title>re: How to move a string into a TMemoryStream or TFileStream.</title>
<author>
<name>Ralph Friedman</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=27334</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=27334</id>
<updated>2000-12-15T08:34:15-08:00</updated>
<published>2000-12-15T08:34:15-08:00</published>
<summary>re: How to move a string into a TMemoryStream or TFileStream.</summary>
<content>In that case, there is no difference between:Pointer(Msg)^andMsg[1]it will still get to the stream. With the 2nd the code will be much easier to decipher by 85% of Delphi developers. The notation doesn't change the contents or the output.</content>
</entry>
<entry>
<title>How to move a string into a TMemoryStream or TFileStream.</title>
<author>
<name>Iain McCallum</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=27332</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=27332</id>
<updated>2000-12-15T05:26:28-08:00</updated>
<published>2000-12-15T05:26:28-08:00</published>
<summary>How to move a string into a TMemoryStream or TFileStream.</summary>
<content>For me, the original 'simplistic' example was exactly therequired solution e.g. you want to send a string's contentsto an application on another computer that expectsthe string length to be expressed as a 4-ascii- character prefix - say '0019This is the message' - youdefinitely don't want any Delphi-specific, or even worse,Delphi-version-specific stuff in there - so the DelphiPointer(Msg)^ or Msg[1] is what's required.I'm using it in a real-world application.</content>
</entry>
<entry>
<title>re: How to move a string into a TMemoryStream or TFileStream.</title>
<author>
<name>Ralph Friedman</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=27329</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=27329</id>
<updated>2000-12-15T01:44:02-08:00</updated>
<published>2000-12-15T01:44:02-08:00</published>
<summary>re: How to move a string into a TMemoryStream or TFileStream.</summary>
<content>Whoops! I inadvertently reposted the original. I've corrected that now. The original may have been simplistic, but it was definitely not practical. I added the ability to store the string length. I also used Pascal notation as opposed to the C++ notation that was in the original example</content>
</entry>
<entry>
<title>How to move a string into a TMemoryStream or TFileStream.</title>
<author>
<name>Ralph Friedman</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=27323</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=27323</id>
<updated>2000-12-15T01:42:21-08:00</updated>
<published>2000-12-15T01:42:21-08:00</published>
<summary>How to move a string into a TMemoryStream or TFileStream.</summary>
<content>The method presented is fine in the unlikely event that one is storing a singe string to a stream. The following rewrite takes into consideration the possibility that the goal is to store more than one string:procedure TForm1.Button1Click(Sender: TObject);var  lng:          integer;  MemoryStream: TMemoryStream;  SourceString: string;begin  SourceString := 'Hello, how are you doing today?';  MemoryStream := TMemoryStream.Create;  try    // Write the length of the string to the stream:    lng := Length(SourceString);    MemoryStream.WriteBuffer(lng, SizeOf(lng));    // Write the string to the stream. We want to write from SourceString's    // data, starting at a pointer to SourceString (this returns a pointer to    // the first character), dereferenced (this gives the actual character).    MemoryStream.WriteBuffer(SourceString[1], Length(SourceString));    // Go back to the start of the stream    MemoryStream.Position := 0;    // Read it back in to make sure it worked.    // Set the length, so we have space to read into    MemoryStream.ReadBuffer(lng, SizeOf(lng);    SetLength(SourceString, lng);    MemoryStream.ReadBuffer(SourceString[1], lng);    Caption := SourceString;  finally    MemoryStream.Free;  end;end;</content>
</entry>
<entry>
<title>re: How to move a string into a TMemoryStream or TFileStream.</title>
<author>
<name>Corbin Dunn</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=27327</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=27327</id>
<updated>2000-12-14T15:50:04-08:00</updated>
<published>2000-12-14T15:50:04-08:00</published>
<summary>re: How to move a string into a TMemoryStream or TFileStream.</summary>
<content>Ralph - what was the change you made? - the example was made to be highly simplistic.</content>
</entry>
<entry>
<title>re: How to move a string into a TMemoryStream or TFileStream.</title>
<author>
<name>Corbin Dunn</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=27326</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=27326</id>
<updated>2000-12-14T15:44:01-08:00</updated>
<published>2000-12-14T15:44:01-08:00</published>
<summary>re: How to move a string into a TMemoryStream or TFileStream.</summary>
<content>True...and both ways work fine. I wrote this article due to a support phone call on &quot;how do I do it&quot;. I copied it from the VCL...</content>
</entry>
<entry>
<title>How to move a string into a TMemoryStream or TFileStream.</title>
<author>
<name>Iain McCallum</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=27310</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=27310</id>
<updated>2000-12-12T22:38:00-08:00</updated>
<published>2000-12-12T22:38:00-08:00</published>
<summary>How to move a string into a TMemoryStream or TFileStream.</summary>
<content>I got this solution from the ObjectPascal newsgroup:MemoryStream.Write(SourceString[1], Length(SourceString));This is more like Delphi - elegant and transparent - less likeC++ - cryptic and opaque !</content>
</entry>
</feed>
