Board index » delphi » Assigning string to TRichEdit

Assigning string to TRichEdit

I have a string (MyString in this example) that
contains RTF formatted text.
How can I assign this string to a TRichEdit so that
the TRichEdit displays the formatted text instead
of the RTF code?

this doesn't work because it doesn't recognize the
formatting:
TRichEdit.Text := MyString;

this doesn't work either:
var
  St : TStringStream;
begin
  St := TStringStream.Create (MyString);
  try
    St.Seek (0, soFromBeginning);
    dfRichEdit.Lines.LoadFromStream (St);
  finally
    St.Free;
  end;
end;

--Joe

 

Re:Assigning string to TRichEdit


Quote
In article <86hhtn$m...@bornews.borland.com>, Joe Meyer wrote:
> I have a string (MyString in this example) that
> contains RTF formatted text.
> How can I assign this string to a TRichEdit so that
> the TRichEdit displays the formatted text instead
> of the RTF code?

> this doesn't work either:
> var
>   St : TStringStream;
> begin
>   St := TStringStream.Create (MyString);
>   try
>     St.Seek (0, soFromBeginning);
>     dfRichEdit.Lines.LoadFromStream (St);

It should in fact work if dfRichedit.Plaintext is false (an the
control is not a TDBRichedit!) and MyString contains a properly
formed RTF chunk. This has to be syntactically complete RTF file,
you know, starting with {\rtf1 and ending with a }, e.g.

  '{\rtf1\ansi\pard\plain 12{\ul 44444}}'

To force a specific font you will need a font table, if you use
colors other than the default black you need a color table. RTF is
not a format that allows you to simply put any odd sequence of RTF
tokens into the control, you know, it is picky in the extreme.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Sent using Virtual Access 5.00 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Re:Assigning string to TRichEdit


Quote
> I have a string that contains RTF formatted text.
> How can I assign this string to a TRichEdit so that
> the TRichEdit displays the formatted text instead
> of the RTF code?

Go to Deja.com and search under "EM_STREAMIN" and "Peter Below" to find code.
EM_STREAMIN is documented in the Win32.hlp file.

Other Threads