BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to read TMemoryStream contents to AnsiString?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
dzeidzei
Guest





PostPosted: Tue Nov 15, 2005 5:36 am    Post subject: How to read TMemoryStream contents to AnsiString? Reply with quote




Hi,
I have a TMemoryStream containing string(s), (response from IdHTTP->Post), and I'd like to put that response to AnsiString.

And don't know how to do that. Could someone help?

- dzeidzei
Back to top
JD
Guest





PostPosted: Tue Nov 15, 2005 6:30 am    Post subject: Re: How to read TMemoryStream contents to AnsiString? Reply with quote




"dzeidzei" <dzeidzei (AT) suolakaivos (DOT) com> wrote:
Quote:

I have a TMemoryStream containing string(s), [...] I'd like
to put that response to AnsiString.

Use a TStringList and it's LoadFromStream method.

~ JD


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Nov 15, 2005 7:19 am    Post subject: Re: How to read TMemoryStream contents to AnsiString? Reply with quote




"dzeidzei" <dzeidzei (AT) suolakaivos (DOT) com> wrote


Quote:
I have a TMemoryStream containing string(s), (response
from IdHTTP->Post), and I'd like to put that response to
AnsiString.

Why not just use the overloaded version of Post() that returns an AnsiString
instead of filling a TStream? You do know that TIdHTTP has several
overloaded methods, right?

If you must continue using a TMemoryStream, then cast the TMemoryStream's
Memory property to char*, ie:

AnsiString str( (char*) stream->Memory, stream->Size );

Alternatively:

AnsiString str;
str.SetLength(stream->Size);
stream->Position = 0;
stream->Read(str.c_str(), stream->Size);

Or, use a TStringStream instead of a TMemoryStream. TStringStream has a
DataString property that already contains the stream content as an
AnsiString.


Gambit



Back to top
dzeidzei
Guest





PostPosted: Tue Nov 15, 2005 12:40 pm    Post subject: Re: How to read TMemoryStream contents to AnsiString? Reply with quote


"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

Why not just use the overloaded version of Post() that returns an AnsiString
instead of filling a TStream? You do know that TIdHTTP has several
overloaded methods, right?

Unfortunately, my Indy lib is so old that it only supports TMemoryStream :-(

But I got it done with TStringStream, as You arvised.

Thanks!

- dzeidzei

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Nov 16, 2005 10:02 pm    Post subject: Re: How to read TMemoryStream contents to AnsiString? Reply with quote


"dzeidzei" <dzeidzei (AT) suolakaivos (DOT) com> wrote


Quote:
Unfortunately, my Indy lib is so old that it only supports TMemoryStream
Sad


Then you should serously consider upgrading to a newer version.


Gambit



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.