Sign in Join
Wiki copytemporary

TFindDialog/zh CN: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11**TFindDialog** ![](/wiki-images/9/9e/Tfinddialog.png) 是搜索的弹出对话框. 在 [[Dialogs tab]] 的 [[Component Palette]].
22
33对话框本身不会搜索; 仅仅是为搜索参数提供一个界面而已. 激活搜索框, 使用方法:`Execute()` [[Function|function]]. 创建 `OnFind` [[Method|method]] 然后咋其中搜索.
44
5-<figure>
6-<img src="component-TFindDialog.png" title="component-TFindDialog.png" />
7-<figcaption>component-TFindDialog.png</figcaption>
8-</figure>
5+![](/wiki-images/3/33/Component-TFindDialog.png)
96
107## 用法
118
129如下示例显示了使用TFindDialog在([[TMemo]])中搜索特定内容的方法.
1310
1411``` pas
1512procedure TForm1.Button1Click(Sender: TObject);
1613begin
1714 FindDialog1.Execute();
1815end;
1916
2017procedure TForm1.FindDialog1Find(Sender: TObject);
2118var
2219 k: integer;
2320begin
2421 with Sender as TFindDialog do begin
2522 k := Pos(FindText, Memo1.Lines.Text);
2623 if k > 0 then begin
2724 Memo1.SelStart := k - 1;
2825 Memo1.SelLength := Length(FindText);
2926 Memo1.SetFocus; //必须激活控件,否则不显示选择效果
3027 end else
3128 Beep();
3229 end;
3330end;
3431```
3532
3633如果要继续搜索同样的内容,必须记住最后一次搜索的位置,从此处继续搜索。 [[Unit|unit]] 中的`PosEx()` 就是用来标记位置的:
3734
3835``` pas
3936uses
4037 StrUtils;
4138
4239type
4340 TForm1 = class(TForm)
4441 private
4542 FFoundPos: Integer;
4643 ...
4744
4845procedure TForm1.Button1Click(Sender: TObject);
4946begin
5047 with FindDialog1 do
5148 begin
5249 if frEntireScope in Options then // Search begins at file start
5350 FFoundPos := 0
5451 else
5552 FFoundPos := Memo1.SelStart; // Serach begins at current cursor position
5653 Execute;
5754 end;
5855end;
5956
6057procedure TForm1.FindDialog1Find(Sender: TObject);
6158begin
6259 with Sender as TFindDialog do
6360 begin
6461 FFoundPos := PosEx(FindText, Memo1.Lines.Text, FFoundPos+1);
6562 if FFoundPos > 0 then
6663 begin
6764 Memo1.SelStart := FFoundPos - 1;
6865 Memo1.SelLength := Length(FindText);
6966 Memo1.SetFocus; //必须激活控件,否则不显示选择效果
7067 end else
7168 Beep();
7269 end;
7370end;
7471```
7572
7673## 参考资料
7774
7875- [[doc:lcl/dialogs/tfinddialog.html|TFindDialog doc]]
7976- [[TReplaceDialog]]
8077
8178---
8279*From the Free Pascal wiki, page "TFindDialog/zh CN", as it stood on 2020-05-01 after a change by TyphonFinger, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history