Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Color Parsing

Posted on 1997-11-24
5
Medium Priority
?
149 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 400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

688 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