Board index » delphi » Accessing TRichEdit's text including rtf text.

Accessing TRichEdit's text including rtf text.

Folks...

I have a proprietary database that needs to load/save the contents of
a TRichEdit with the rtf codes.  The db can read or write easily from
any old memory buffer.  In essence, I need to be able to take
a TRichEdit and get from (put to) some buffer with the *entire* rich
text, including the rtf formatting info.

The code I have below works.  However, this seems terribly awkward.
Is there some simple way to do this?  I suspect it's staring me right
in the face, but I think I may have thrown a brain-rod or something.
The goal is to produce a string or a TStringList or even just a raw
pbyte that contains the visible text AND the formatting information.

function GetRichEditText(aRichEdit:TRichEdit):string;
        var
                aStream:TMemoryStream;
        begin
        aStream:=TMemoryStream.Create;
        aRichEdit.Lines.SaveToStream(aStream);
        result:=PChar(aStream.Memory);
        aStream.Free;
        end;

procedure SetRichEditText(aRichEdit:TRichEdit;aString:string);
        var
                aStream:TMemoryStream;
        begin
        // (NOTE:  This one's just a guess, I haven't actually tested it)
        aStream:=TMemoryStream.Create;
        aStream.Write(PChar(aString),length(aString));
        aRichEdit.Lines.LoadFromStream(aStream);
        aStream.Free;
        end;

Any insights?

Thanks!
Hill

 

Re:Accessing TRichEdit's text including rtf text.


Hill:

Using the Lines to/from stream methods is about as straight forward as it
gets.

--
Regards
Ralph (TeamB)

Quote
uly_REMOVE_...@mindspring.com wrote in message

<34c4e010.10463...@news.mindspring.com>...
Quote
>Folks...

<deletia>

Quote
>The code I have below works.  However, this seems terribly awkward.
>Is there some simple way to do this?  I suspect it's staring me right
>in the face, but I think I may have thrown a brain-rod or something.
>The goal is to produce a string or a TStringList or even just a raw
>pbyte that contains the visible text AND the formatting information.

<deletia>

Other Threads