Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a problem. I'm using 2 RichE

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
I have a problem. I'm using 2 RichEdit boxes, and I'm sending the text from the first box to the second. I'm using TMemoryStreams so that I can retain the italics, bold, color, etc that the user puts on the text in the first RichEdit box. My problem is as follows:
When The user sends the message, It does a SaveToStream() to my stream, named (ironically) MyStream. I would use LoadFromStream to get the stream into the second rich edit box, except I want to keep what the user wrote before, and LoadFromFile clears the second RichEdit box, so it deletes all of the users previous messages. I need a way to add a line saying what the MemoryStream has in it. I know there has to be a way to do this. I've got code of it being done in Delphi. but when I try to convert it to C++, i get some errors. Heres the delphi code, maybe someone else who knows delphi can help me here. I would sincerely appreciate some code on doing this, because I'm dead stuck.

procedure TForm1.Button1Click(Sender: TObject);
var
SourceString: string;
MemoryStream: TMemoryStream;
begin
SourceString := 'Hello, how are you doing today?';
MemoryStream := TMemoryStream.Create;
try
// 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(Pointer(SourceString)^, Length(SourceString));
// Go back to the start of the stream
MemoryStream.Position := 0;
// Read it back in to make sure it worked.
SourceString := 'I am doing just fine!';
// Set the length, so we have space to read into
SetLength(SourceString, MemoryStream.Size);
MemoryStream.ReadBuffer(Pointer(SourceString)^, MemoryStream.Size);
Caption := SourceString;
finally
MemoryStream.Free;
end;
end;

having a keen eye for the obvious, i noted that it used ReadBuffer, but when i try that with my String, it says cant convert from AnsiString to void, duh. But I don't know how to convert from AnsiString to void. i guess the 'Pointer' function would work, except I got errors when trying it, so I took out the ^. and it again, said cannot convert from AnsiString to void. Now I desperately need help.
I have to use a TMemoryStream, I can't cut to the clipboard or anything to get the desired result.

Thanks alot!!
Cyprus
 
I can tell you allready how to convert from AnsiString to void :


AnsiString MyString;
(void*) Mystring.c_str();

c_str() gives the char string (0 terminated) and (void*) castes this pointer to a void pointer.

Does this help you a little bit ? Wim Vanherp
Wim.Vanherp@myself.com
 
I think my previous answer will not work for your application.

This should be better to cast the AnsiString to void ptr

AnsiString MyString;
void *ptr= (void*) &MyString;

In my previous answer you got a pointer to a char string and that will not be what you need, this gives you really the pointer to the AnsiString Wim Vanherp
Wim.Vanherp@myself.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top