Solved

Using the Rich Edit Component

Posted on 1997-11-27
4
217 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
Comment Utility
 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
Comment Utility
Why don't you just use some components which already implement this?
0
 
LVL 7

Accepted Solution

by:
ahalya earned 200 total points
Comment Utility
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
Comment Utility
It's works but I think it's a bit too slow...
Any other way to speed it up??
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now