[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Using the Rich Edit Component

Posted on 1997-11-27
4
Medium Priority
?
226 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
[X]
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
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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 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