Solved

Color Parsing

Posted on 1997-11-24
5
147 Views
Last Modified: 2010-04-04
I want to display text on a trichedit component with different colors. I use a memory stream to enter raw rtf codes. But now my problem is how can i add the stream to the richedit leaving the contenent in tact.

Regards, Arijan
0
Comment
Question by:byte
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1351658
Hi

Try the following:
procedure FillRichEdit(ARichEdit: TRichEdit);
var
  MS: TMemoryStream;
begin
  MS := TMemoryStream.Create;

  // Fill memory stream with codes.
  // E.g.  MS.LoadFromFile('C:\Test.rtf');

  ARichEdit.Lines.LoadFromStream(MS);
  MS.Free;
end;

Regards,
JB
0
 

Author Comment

by:byte
ID: 1351659
Thanks i was so far =) but the problem with this method is that the contents of the richedit will be erased. I want to keep it.

Regards, Byte
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1351660
If you want to append to the existing text then why not save to the memory stream first, then add to the stream, then load it again?

The other way is to send the rich edit control an EM_STREAMIN message, but it's a lot more work and you have to provide a callback function.  I can give you a sample of this if you need one.

JB
0
 

Author Comment

by:byte
ID: 1351661
That would be great. Thx!
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 200 total points
ID: 1351662
The following sample inserts text at the position of the cursor.
My RichEdit control is called rchTest.

uses
  ..., RichEdit;

var
  RichMemStream: TMemoryStream;

function EdStreamCallBack(dwCookie: Longint; pbBuff: PByte; cb: Longint; var pcb: Longint): Longint; stdcall;
begin
  CopyMemory(pbBuff, RichMemStream.Memory, RichMemStream.Size);
  pcb := RichMemStream.Size;
  Result := NOERROR;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  EdStream: TEditStream;
begin
  RichMemStream := TMemoryStream.Create;

  RichMemStream.LoadFromFile('C:\Test.txt');

  FillChar(EdStream, SizeOf(TEditStream), 0);
  EdStream.pfnCallback := @EdStreamCallBack;

  RichMemStream.Position := 0;
  rchTest.Perform(EM_STREAMIN, SF_RTF or SFF_SELECTION, Integer(@EdStream));

  RichMemStream.Free;
end;


Note that I fill the memory stream by loading it from C:\Test.txt, which has the following content:

{\rtf1\ansi\deff0\deftab720
{\fonttbl{\f0\fswiss MS Sans Serif;}
{\f1\froman\fcharset2 Symbol;}
{\f2\fswiss\fcharset1 MS Sans Serif;}}
{\colortbl\red0\green0\blue0;}
\deflang1033\pard\plain\f2\fs16
\par \b Hello there.\plain
}


Regards,
JB
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 88
TServerSocket - file via sendbuf or Text via sendtext ? 1 92
firemonkey keyboard covers the controls 1 83
DBCtrlGrid, Delphi, Scroll 7 35
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question