初めて質問します。当方初心者です。宜しくお願いします。
文字検索エディタを作っています。
RichEditに文書を読み込ませ、その中から文字列を検索させることはできました。
RichEdit内にイタリック体文字や太文字が含まれている場合に、対応するFontを指定して検索したいです(Wordの検索オプションのように)。
そのような事が可能な関数はあるのでしょうか?
皆目見当がつきません。
何か手掛かりがあれば教えて頂きたいです。お願いします。
すみません、使用しているのはDelphi6です。
レスつかないようなので簡単な例を
起動時フォント名を読み込んだ ComboBox を置きます
(Style = csDropDownList で)
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.AddStrings(Screen.Fonts);
end;
そのフォント名を見つける方法
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
with RichEdit1 do
begin
for i:=0 to Length(RichEdit1.Lines.Text)-2 do
begin
SelStart:=i;
SelLength:=1;
if SelAttributes.Name=ComboBox1.Text then Break;
end;
SelStart:=i;
SelLength:=1;
SetFocus;
end;
end;
ベタなので一つ目を見つけたら疲れてやめてしまいますし、長いものではスピードも望めませんがとりあえずこんな感じです
あ、今読み返したら「イタリック体文字や太文字」ですね
SelAttributes.Name を SelAttributes.Style に変えて
ComboBox は TRadioGroup にでも変えてください
内容を
◎太字
◎斜体
◎下線
◎打ち消し線付き
にして
case RadioGroup1.ItemIndex of
0:if fsBold in SelAttributes.Style then Break;
1:if fsItalic in SelAttributes.Style then Break;
2:if fsUnderline in SelAttributes.Style then Break;
3:if fsStrikeout in SelAttributes.Style then Break;
end;
なんか不細工(^^;
だれかスマートな方法を…
>けどさん
本当にありがとうございます、なんとかなりそうな感じがしてきました!
ところで、RadioGroupの選択で「SelAttributesが未定義です」と出るのですが、定義の仕方はどうやったらよいでしょうか?
色々調べてやってみましたが、どこにどのように宣言したら良いのかわりません。
すみません 20:42:18 の ComboBox と差し替えのつもりで書きました
with RichEdit1 do がついて SelAttributes は TRichEdit の
プロパティです
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
with RichEdit1 do
begin
for i:=0 to Length(RichEdit1.Lines.Text)-2 do
begin
SelStart:=i;
SelLength:=1;
case RadioGroup1.ItemIndex of
0:if fsBold in SelAttributes.Style then Break;
1:if fsItalic in SelAttributes.Style then Break;
2:if fsUnderline in SelAttributes.Style then Break;
3:if fsStrikeout in SelAttributes.Style then Break;
end;
end;
SelStart:=i;
SelLength:=1;
SetFocus;
end;
end;
>けどさん
本当にありがとうございました!助かりましたm(_ _)m
ツイート | ![]() |