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
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