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
Solved

Using the Rich Edit Component

Posted on 1997-11-27
4
220 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 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