Board index » delphi » Saving MemoryStream to string

Saving MemoryStream to string

How can I save memory stream to string ?
 

Re:Saving MemoryStream to string


In message <39f470f3$1_1@dnews>, Pr stated:

Quote
> How can I save memory stream to string ?

var
  mStream:    TMemoryStream;
  thisString: string;
begin
  mStream := TMemoryStream.Create;
  try
    mStream.LoadFromFile('Unit1.Pas');

    if mStream.Size > 0 then begin
      SetLength(thisString, mStream.Size);
      Move(mStream.Memory^, thisString[1], mStream.Size);
    end;
  finally
    mStream.Free;
  end;

  if Length(thisString) > 0 then
    RichEdit1.Text := thisString;
end;

--
Regards
Ralph (TeamB)
===

Re:Saving MemoryStream to string


SetLength(aString,MemStream.Size);
MemStream.Write(aString[1],MemStream.Size)
Quote
PR wrote:
> How can I save memory stream to string ?

Re:Saving MemoryStream to string


PR <emai...@nowhere.com> schreef in berichtnieuws 39f470f3$1_1@dnews...

Quote
> How can I save memory stream to string ?

TheString: string;
TheStream: TmemoryStream;
..
TheStream := TMemoryStream.Create;
< your code >
SetLength( TheString, TheStream.Size);
TheStream.Position := 0;
TheStream.Write( TheString[1], Length(TheString));
TheStream.Free;

--
Regards,

Dirk Claessens
---------------------------------------------------------
http://www.claessens16.yucom.be
Attention: All spamshields raised; E-mails will bounce!
---------------------------------------------------------

Re:Saving MemoryStream to string


Quote
Glynn Owen wrote...
> SetLength(aString,MemStream.Size);
> MemStream.Write(aString[1],MemStream.Size)

MemStream.Read(aString[1], MemStream.Size)
                    ~~~~
--
Pieter

Re:Saving MemoryStream to string


Oops. Sure hope he didn't overwrite an important file...
Thanks for the correction.
Glynn
Quote
Pieter Zijlstra wrote:
> Glynn Owen wrote...
> > SetLength(aString,MemStream.Size);
> > MemStream.Write(aString[1],MemStream.Size)

> MemStream.Read(aString[1], MemStream.Size)
>                     ~~~~
> --
> Pieter

Re:Saving MemoryStream to string


thanks for the help..

Quote
"Glynn Owen" <glynno...@home.com> wrote in message

news:39F4ADE2.3DF96A6D@home.com...
Quote
> Oops. Sure hope he didn't overwrite an important file...
> Thanks for the correction.
> Glynn

> Pieter Zijlstra wrote:

> > Glynn Owen wrote...
> > > SetLength(aString,MemStream.Size);
> > > MemStream.Write(aString[1],MemStream.Size)

> > MemStream.Read(aString[1], MemStream.Size)
> >                     ~~~~
> > --
> > Pieter

Re:Saving MemoryStream to string


Quote
"Glynn Owen" wrote:
> SetLength(aString,MemStream.Size);
> MemStream.[Read](aString[1],MemStream.Size)

This is a little faster and easier:
SetString(aString, MemStream.Memory, MemStream.Size):

Other Threads