TFindDialog/zh CN: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | **TFindDialog**  是搜索的弹出对话框. 在 [[Dialogs tab]] 的 [[Component Palette]]. | |
| 2 | 2 | ||
| 3 | 3 | 对话框本身不会搜索; 仅仅是为搜索参数提供一个界面而已. 激活搜索框, 使用方法:`Execute()` [[Function|function]]. 创建 `OnFind` [[Method|method]] 然后咋其中搜索. | |
| 4 | 4 | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 8 | - | ||
| 5 | + |  | |
| 9 | 6 | ||
| 10 | 7 | ## 用法 | |
| 11 | 8 | ||
| 12 | 9 | 如下示例显示了使用TFindDialog在([[TMemo]])中搜索特定内容的方法. | |
| 13 | 10 | ||
| 14 | 11 | ``` pas | |
| 15 | 12 | procedure TForm1.Button1Click(Sender: TObject); | |
| 16 | 13 | begin | |
| 17 | 14 | FindDialog1.Execute(); | |
| 18 | 15 | end; | |
| 19 | 16 | ||
| 20 | 17 | procedure TForm1.FindDialog1Find(Sender: TObject); | |
| 21 | 18 | var | |
| 22 | 19 | k: integer; | |
| 23 | 20 | begin | |
| 24 | 21 | with Sender as TFindDialog do begin | |
| 25 | 22 | k := Pos(FindText, Memo1.Lines.Text); | |
| 26 | 23 | if k > 0 then begin | |
| 27 | 24 | Memo1.SelStart := k - 1; | |
| 28 | 25 | Memo1.SelLength := Length(FindText); | |
| 29 | 26 | Memo1.SetFocus; //必须激活控件,否则不显示选择效果 | |
| 30 | 27 | end else | |
| 31 | 28 | Beep(); | |
| 32 | 29 | end; | |
| 33 | 30 | end; | |
| 34 | 31 | ``` | |
| 35 | 32 | ||
| 36 | 33 | 如果要继续搜索同样的内容,必须记住最后一次搜索的位置,从此处继续搜索。 [[Unit|unit]] 中的`PosEx()` 就是用来标记位置的: | |
| 37 | 34 | ||
| 38 | 35 | ``` pas | |
| 39 | 36 | uses | |
| 40 | 37 | StrUtils; | |
| 41 | 38 | ||
| 42 | 39 | type | |
| 43 | 40 | TForm1 = class(TForm) | |
| 44 | 41 | private | |
| 45 | 42 | FFoundPos: Integer; | |
| 46 | 43 | ... | |
| 47 | 44 | ||
| 48 | 45 | procedure TForm1.Button1Click(Sender: TObject); | |
| 49 | 46 | begin | |
| 50 | 47 | with FindDialog1 do | |
| 51 | 48 | begin | |
| 52 | 49 | if frEntireScope in Options then // Search begins at file start | |
| 53 | 50 | FFoundPos := 0 | |
| 54 | 51 | else | |
| 55 | 52 | FFoundPos := Memo1.SelStart; // Serach begins at current cursor position | |
| 56 | 53 | Execute; | |
| 57 | 54 | end; | |
| 58 | 55 | end; | |
| 59 | 56 | ||
| 60 | 57 | procedure TForm1.FindDialog1Find(Sender: TObject); | |
| 61 | 58 | begin | |
| 62 | 59 | with Sender as TFindDialog do | |
| 63 | 60 | begin | |
| 64 | 61 | FFoundPos := PosEx(FindText, Memo1.Lines.Text, FFoundPos+1); | |
| 65 | 62 | if FFoundPos > 0 then | |
| 66 | 63 | begin | |
| 67 | 64 | Memo1.SelStart := FFoundPos - 1; | |
| 68 | 65 | Memo1.SelLength := Length(FindText); | |
| 69 | 66 | Memo1.SetFocus; //必须激活控件,否则不显示选择效果 | |
| 70 | 67 | end else | |
| 71 | 68 | Beep(); | |
| 72 | 69 | end; | |
| 73 | 70 | end; | |
| 74 | 71 | ``` | |
| 75 | 72 | ||
| 76 | 73 | ## 参考资料 | |
| 77 | 74 | ||
| 78 | 75 | - [[doc:lcl/dialogs/tfinddialog.html|TFindDialog doc]] | |
| 79 | 76 | - [[TReplaceDialog]] | |
| 80 | 77 | ||
| 81 | 78 | --- | |
| 82 | 79 | *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).* |
