Solved

Color Sintax in Richedit

Posted on 1998-10-04
6
200 Views
Last Modified: 2013-11-22
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
Comment
Question by:sabadao
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:BoRiS
ID: 1341719
sabadao

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

Later
BoRiS
0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1341720
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
 

Author Comment

by:sabadao
ID: 1341721
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:sabadao
ID: 1341722
And these procedure pick the first word only. I need a procedure , that could test all the words.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341723
Ok, I'll test for w while and give you the finaly procedure that works.... Is that OK???

//Viktor
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341724
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

827 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