Memo highligher

i would like to be able to highlight the seleced text in a selected colour in a tmemo but i can not download components or install anything. it must also be highlighted when the file is opened again (save the fact that it has been highlighted). i must be able to high light more than the one part as well (similar to word). i do not want a reply if it is not possible because it is a waste of points and i only want code that will certainly work no guessing pls
LVL 2
gangsterbossAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MrMidiCommented:
Bad news is, you can't do that with a TMemo. Good news is, you can do it with a TRichEdit.
gangsterbossAuthor Commented:
well how
DetiCommented:
First download Synedit package

1. www.sourceforge.net
2. Search "SynEdit" - there will be it
3. Download and install package (stable version, not new CVS)
4. There are demos how to do it - just search.
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

gangsterbossAuthor Commented:
deti u been helpful before but read the question no downloads
DetiCommented:
but TMemo class not support highlighter in fragments of text - it is imposible.
gangsterbossAuthor Commented:
well wot about trichedit then
doporsCommented:
Use OnDrawItem to Highlight the specied text
gangsterbossAuthor Commented:
i need the code cos i aint to good at this
DetiCommented:
I not going to paste code here, because I don`t have one, but :

- try to find pos('sometext', RichEdit.Text);
- for loop if this pos is >0 then select this word
- RichEdit.SelAttributes.Color := clBlue; // set color of selected text as blue

doporsCommented:
I Found out that there is no OnDrawItem on TMemo
I will use TRichEdit

procedure Form1.ColorizedWord(oRichedit : TRichedit; sWord : String; oColor : TColor);
var
 iFoundAt,
 iSelStart,
 iSelLength : Integer;
begin
 iSelStart := oRichedit.SelStart;
 iSelLength := oRichedit.SelLength;
 try
   iFoundAt := -1;
   repeat
     iFoundAt := oRichedit.FindText(sWord,iFoundAt+1,length(oRichedit.Text),[stWholeWord]);
     if iFoundAt > -1 then
     begin
       oRichedit.SelStart := iFoundAt;
       oRichedit.SelLength := length(sWord);
       oRichedit.SelAttributes.Color := oColor;
     end;
   until iFoundAt = -1;
 finally
   oRichedit.SelStart := iSelStart;
   oRichedit.SelLength := iSelLength;
 end;
end;

procedure Form1.SpeedButton1Click(Sender: TObject);
begin
     ColorizedWord(RichEdit1, Edit1.Text, clRed) //
end;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gangsterbossAuthor Commented:
can u redo this code so it only does the richedit1.seltext instead of them all and comment each part cos i don't have a clue how this works and i am trying to learn
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.