Board index » delphi » sending actual Rich Text to a Rich Edit

sending actual Rich Text to a Rich Edit

does anyone know how to append actual strings of Rich Text to a rich edit?
if i just assign the strings, it treats the rich text as plain text, and
displays all the format characters, instead of using them.

I could open a text file, output my rich text to it, and then use
Lines.LoadFromFile, but Id rather be able to do it without resorting to
files.

cheers,

ben

 

Re:sending actual Rich Text to a Rich Edit


Quote
In article <8lm4qh$c...@bornews.borland.com>, Ben Dixon wrote:
> does anyone know how to append actual strings of Rich Text to a rich edit?

See my answer in today's "Appending to TRichEdit" thread.

 Mike Orriss (TeamB & Developer Express)
 (Unless stated otherwise, my replies relate to Delphi 5)
 (No unsolicited e-mail replies please)

Re:sending actual Rich Text to a Rich Edit


this hasnt helped me much.

I tried this, bit it just loaded my Rich Text in as plain text:

procedure TForm1.Button1Click(Sender: TObject);
var
  TempStream : TMemoryStream;
  St:String;
begin
   St:='{\rtf1\ansi\ansicpg1252\deff0\deftab720'+#13#10
      +'  {\fonttbl{\f0\fmodern Courier New;}'+#13#10
      +'  {\colortbl\red0\green0\blue0;'+#13#10
      +'\pard\plain\f0\fs24\b\ '+'testing!!!'+#13#10
      +'\par}'+#13#10;

   TempStream := TMemoryStream.Create;
   try
     TempStream.WriteBuffer(Pointer(St)^, Length(St));
     TempStream.Position := 0;

     RichEdit1.LoadFromStream(TempStream);

   finally
     TempStream.Free;
   end;
end;

Then I tried the following adaption of your code, without success - it didnt
import any text at all:

procedure TForm1.Button1Click(Sender: TObject);
var
  TempStream : TMemoryStream;
  St:String;
begin
   St:='{\rtf1\ansi\ansicpg1252\deff0\deftab720'+#13#10
      +'  {\fonttbl{\f0\fmodern Courier New;}'+#13#10
      +'  {\colortbl\red0\green0\blue0;'+#13#10
      +'\pard\plain\f0\fs24\b\ '+'testing!!!'+#13#10
      +'\par}'+#13#10;

   TempStream := TMemoryStream.Create;
   try
     TempStream.WriteBuffer(Pointer(St)^, Length(St));
     TempStream.Position := 0;

     PutRTF(RichEdit1,TempStream);

   finally
     TempStream.Free;
   end;
end;

any clues as to what I'm doing wrong?

cheers,
ben

Mike Orriss (TeamB) <m...@3kcc.co.uk> wrote in message
news:VA.00001b4f.0040b5b1@mikemain...

Quote
> In article <8lm4qh$c...@bornews.borland.com>, Ben Dixon wrote:
> > does anyone know how to append actual strings of Rich Text to a rich
edit?

> See my answer in today's "Appending to TRichEdit" thread.

>  Mike Orriss (TeamB & Developer Express)
>  (Unless stated otherwise, my replies relate to Delphi 5)
>  (No unsolicited e-mail replies please)

Re:sending actual Rich Text to a Rich Edit


oops!  the line that reads:

  RichEdit1.LoadFromStream(TempStream);

should read:

    RichEdit1.Lines.LoadFromStream(TempStream);

cheers,

ben

Re:sending actual Rich Text to a Rich Edit


Quote
In article <8lo1lj$t...@bornews.borland.com>, Ben Dixon wrote:
> any clues as to what I'm doing wrong?

Yes, your input string does not contain valid RTF formatting (non-matching
number of '{' & '}', for example). When I replaced your string with a
valid one, the first version worked perfectly for me (I didn't bother with
the second).

 Mike Orriss (TeamB & Developer Express)
 (Unless stated otherwise, my replies relate to Delphi 5)
 (No unsolicited e-mail replies please)

Other Threads