⌊ K™¦krizzna.web.id ⌉

Sekedar coretan seorang nyubi

Q&A: Delphi programming?

Posted on

Question by Jigsaw K: Delphi programming?
Hello,

I’m making a program which consists of a RichEdit. I have set a function using StringFind and StringReplace to find and replace the word ‘cool’ in an example, the thing I want to do is to replace the color of the specific word cool. So in example:

all the colors were blue, green, cool <----- the word 'cool' must be blue in the example, so how can I replace color of an especific word in Delphi? Thank you very much, please answer as soon as possible.

Best answer:

Answer by reinandang
It’s easy, i’ll show you :

procedure TForm1.FindDialog1Find(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd: Integer;
begin
with RichEdit1 do
begin

{ begin the search after the current selection if there is one }
{ otherwise, begin at the start of the text }
if SelLength <> 0 then

StartPos := SelStart + SelLength
else

StartPos := 0;

{ ToEnd is the length from StartPos to the end of the text in the rich edit control }

ToEnd := Length(Text) – StartPos;

FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
if FoundAt <> -1 then
begin
SetFocus;
SelStart := FoundAt;
SelLength := Length(FindDialog1.FindText);

{Set Font Color here}
SelAttributes.Color:=clBlue;

end;

end;

end;

Add your own answer in the comments!

Share and Enjoy:
  • printfriendly Q&A: Delphi programming?
  • digg Q&A: Delphi programming?
  • delicious Q&A: Delphi programming?
  • facebook Q&A: Delphi programming?
  • yahoobuzz Q&A: Delphi programming?
  • twitter Q&A: Delphi programming?
  • googlebookmark Q&A: Delphi programming?
  • email link Q&A: Delphi programming?
  • linkedin Q&A: Delphi programming?
  • live Q&A: Delphi programming?
  • myspace Q&A: Delphi programming?
  • pdf Q&A: Delphi programming?
  • plurk Q&A: Delphi programming?
  • slashdot Q&A: Delphi programming?
  • technorati Q&A: Delphi programming?
  • tumblr Q&A: Delphi programming?
  • hackernews Q&A: Delphi programming?

Tags: ,