RichEdit1
FindText (Delphi)
描述
此示例需要一个 TRichEdit、一个 TButton 和一个 TFindDialog。单击“单击”按钮将在编辑控件的右侧显示“查找”对话框。填写“查找内容”文本并单击“查找下一个”按钮将在“丰富编辑”控件中选择上一个选择之后的第一个匹配字符串。
法典
procedure TForm1.Button1Click(Sender: TObject);
begin
FindDialog1.Position :=
Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
FindDialog1.Execute;
end;
procedure TForm1.FindDialog1Find(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd: Integer;
mySearchTypes : TSearchTypes;
myFindOptions : TFindOptions;
begin
mySearchTypes := [];
with RichEdit1 do
begin
if frMatchCase in FindDialog1.Options then
mySearchTypes := mySearchTypes + [stMatchCase];
if frWholeWord in FindDialog1.Options then
mySearchTypes := mySearchTypes + [stWholeWord];
{ Begin the search after the current selection, if there is one. }
{ Otherwise, begin at the start of the text. }
if SelLength <> 0 then
StartPos := SelStart + SelLength
else
StartPos := 0;
{ ToEnd is the length from StartPos through the end of the
text in the rich edit control. }
ToEnd := Length(Text) - StartPos;
FoundAt :=
FindText(FindDialog1.FindText, StartPos, ToEnd, mySearchTypes);
if FoundAt <> -1 then
begin
SetFocus;
SelStart := FoundAt;
SelLength := Length(FindDialog1.FindText);
end
else Beep;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
const Path = 'OverView.RTF';
begin
RichEdit1.PlainText := False;
RichEdit1.Lines.LoadFromFile(Path);
RichEdit1.ScrollBars := ssVertical;
end;
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.059983968734741 seconds