Solved

Using the Rich Edit Component

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 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