Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to search for a certain font style in a TRichEdit Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
12-Oct-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
62
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to search for a certain font style in a TRichEdit

Answer:

Finding all bold-faced words in a TRichEdit control:

1   unit Unit1;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
7   StdCtrls,
8       ComCtrls;
9   
10  type
11    TForm1 = class(TForm)
12      RichEdit1: TRichEdit;
13      ListBox1: TListBox;
14      Button1: TButton;
15      procedure Button1Click(Sender: TObject);
16    private
17      { Private declarations }
18    public
19      { Public declarations }
20    end;
21  
22  var
23    Form1: TForm1;
24  
25  implementation
26  
27  {$R *.DFM}
28  
29  procedure TForm1.Button1Click(Sender: TObject);
30  var
31    S: string;
32    wordstart, wordend: Integer;
33  begin
34    listbox1.clear;
35    listbox1.setfocus;
36    S := richedit1.text;
37    wordstart := 0;
38    repeat
39      {find start of next word}
40      repeat
41        Inc(wordstart);
42      until
43        (wordstart > Length(S)) or IsCharAlpha(S[wordstart]);
44      if wordstart <= Length(S) then
45      begin
46        {find end of word}
47        wordend := wordstart;
48        repeat
49          Inc(wordend);
50        until
51          (wordend > Length(S)) or not IsCharAlpha(S[wordend]);
52        {we have a word, select it in the rich edit}
53        with richedit1 do
54        begin
55          selstart := wordstart - 1; {character index is 0 based!}
56          sellength := wordend - wordstart;
57          {check the attributes}
58          if (fsBold in SelAttributes.Style) and (caBold in
59            SelAttributes.ConsistentAttributes) then
60            {we have a winna, add it to the listbox}
61            listbox1.items.add(Copy(S, wordstart, wordend - wordstart));
62        end;
63        wordstart := wordend;
64      end;
65    until
66      wordstart >= Length(S);
67  end;
68  
69  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC