Solved

Color Sintax in Richedit

Posted on 1998-10-04
6
199 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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