Solved

Using the Rich Edit Component

Posted on 1997-11-27
4
221 Views
Last Modified: 2010-04-04
I would like to use the Rich Edit component to function like a HTML Editor. (i.e. Whatever that is in the '<>' tag will be color coded)

I also need the color coding to be generated whenever a new character is keyed into the Rich Edit component.

Can anyone teach me how to do it?
You time is greatly appretiated
0
Comment
Question by:ermac
4 Comments
 
LVL 4

Expert Comment

by:StevenB
ID: 1352152
 You'll probably find this question (still unanswered) interesting, as it is basically the same as yours.

http://www.experts-exchange.com/topics/bin/ShowQ?qid=8630022558

  Steven.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1352153
Why don't you just use some components which already implement this?
0
 
LVL 7

Accepted Solution

by:
ahalya earned 200 total points
ID: 1352154
Here is a portion of my code that highlights all "and"s and "or"s in a one line TRichEdit recusively. (i colorize the rich edit on the OnExit event)

if speed is not a big concern then you can do a similar thing
in the onchange event i would guess.

on a line by line basis
   i := find pos of '<'  
   j := pos of '>' starting from i
   highlight from  s[i] to s[j] (see my highlight proc below)
until alldone


procedure TMainForm.RichEditExit(Sender:TObject);

var s    : string;
    i, j : integer;
    SelS, SelL : integer;

procedure HighLight(i, j:integer);

begin;
(Sender As TRichEdit).SelStart := i;
(Sender As TRichEdit).SelLength := j;
(Sender As TRichEdit).SelAttributes.Color := clGrayText;
(Sender As TRichEdit).SelLength := 0;
MainForm.Update;
end;

begin
(Sender As TRichEdit).Text := Trim((Sender As TRichEdit).Text);
SelS :=  (Sender As TRichEdit).SelStart;
SelL :=  (Sender As TRichEdit).SelLength;

s := (Sender As TRichEdit).text;
i := pos(' and ', s);
j := i ;
while i > 0 do
  begin;
  Highlight(j-1, 4);
  Delete(s, 1, i+4);
  i := pos(' and ', s);
  j := j + i + 4;
  end;

s := (Sender As TRichEdit).text;
i := pos(' or ', s);
j := i ;
while i > 0 do
  begin;
  Highlight(j-1, 3);
  Delete(s, 1, i+3);
  i := pos(' or ', s);
  j := j + i + 3;
  end;

(Sender As TRichEdit).SelStart  := SelS;
(Sender As TRichEdit).SelLength := SelL;;
end;


0
 

Author Comment

by:ermac
ID: 1352155
It's works but I think it's a bit too slow...
Any other way to speed it up??
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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…

679 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