Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Color Parsing

Posted on 1997-11-24
5
Medium Priority
?
150 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
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Integration Management Part 2
Suggested Courses

885 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