• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Color Sintax in Richedit

Like to the Word, I need to create a function that underlines some words, when typed, but I don't know to make this.I would like to know if somebody  could help me.
0
sabadao
Asked:
sabadao
  • 3
  • 2
1 Solution
 
BoRiSCommented:
sabadao

You mean if there is an error in spelling or if they choose to underline a word.

Later
BoRiS
0
 
viktornetCommented:
Here is an example of what you want.... Hope it helps... ;->

procedure UnderLine(RichEdit : TRichEdit; sWord : string);
var
  nPos : Integer;
  OldStart;
begin
  nPos := Pos(sWord, RichEdit.Text);
  OldStart := RichEdit.SelStart;
  if nPos > 0 then begin
    RichEdit.SetFocus;
    RichEdit.SelStart := nPos - 1;
    RichEdit.SelLength := Length(sWord);
    RichEdit.SelAttributes.Style := RichEdit.SelAttributes.Style + [fsUnderline];
  end;
  RichEdit.SelStart := OldStart;
end;

//Example call...

procedure TForm1.FormClick(Sender: TObject);
begin
  UnderLine(RichEdit1, 'Hello');
end;

Regards,
Viktor Ivanov
0
 
sabadaoAuthor Commented:
Ok, but I need, to Test all time when the user keypress, and if was correct I need to take out the underline.....Like the delphi too. It underline the reserved word.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
sabadaoAuthor Commented:
And these procedure pick the first word only. I need a procedure , that could test all the words.
0
 
viktornetCommented:
Ok, I'll test for w while and give you the finaly procedure that works.... Is that OK???

//Viktor
0
 
viktornetCommented:
Here is something.....

procedure UnderLine(RichEdit : TRichEdit; sWord : string);
var
  nPos, OldStart, Len : Integer;
begin
  nPos := Pos(sWord, RichEdit.Text);
  OldStart := RichEdit.SelStart;
  RichEdit.SetFocus;
  while nPos > 0 do begin
    RichEdit.SelStart := nPos - 1;
    RichEdit.SelLength := Length(sWord);
    RichEdit.SelAttributes.Style := RichEdit.SelAttributes.Style + [fsUnderline];
    RichEdit.SelLength := 0;
    RichEdit.SelAttributes.Style := RichEdit.SelAttributes.Style - [fsUnderline];
    Len := Pos(sWord, Copy(RichEdit.Text, (nPos-1) + Length(sWord), Length(RichEdit.Text)));
    if Len <> 0 then
        nPos := nPos + (Len+1)
    else
        break;
  end;
  RichEdit.SelStart := OldStart;
end;

Example Call:

Underline(RichEdit1, 'Hello');

Regards,
Viktor Ivanov
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now