TFindDialog/fi: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: TFindDialog/fi
| Old | New | Line | |
|---|---|---|---|
| 1 | + | **TFindDialog**  on komponentti, joka auttaa tiedon etsinnässä. Se löytyy [[Component Palette/fi|komponenttipaletin]] [[Dialogs tab/fi|Dialogs]]-välilehdeltä. On tärkeää tietää, että valintaikkuna ei itse tee hakua; se tarjoaa vain käyttöliittymän kaikille hakuparametreille. Aktivoi FindDialog kutsumalla sen `Execute()` [[Function/fi|funktiota]]. Luo `OnFind`-[[Method/fi|metodi]], jossa itse haku suoritetaan. | |
| 2 | + | ||
| 3 | + | <figure> | |
| 4 | + | <img src="component-TFindDialog.png" title="component-TFindDialog.png" /> | |
| 5 | + | <figcaption>component-TFindDialog.png</figcaption> | |
| 6 | + | </figure> | |
| 7 | + | ||
| 8 | + | ## Käyttö | |
| 9 | + | ||
| 10 | + | Seuraavat esimerkit kuvaavat TFindDialog-sovelluksen käyttöä muistioon ([[TMemo/fi|TMemo]]) tallennetun tietyn lauseen etsimiseen. | |
| 11 | + | ||
| 12 | + | ``` pas | |
| 13 | + | procedure TForm1.Button1Click(Sender: TObject); | |
| 14 | + | begin | |
| 15 | + | FindDialog1.Execute(); | |
| 16 | + | end; | |
| 17 | + | ||
| 18 | + | procedure TForm1.FindDialog1Find(Sender: TObject); | |
| 19 | + | var | |
| 20 | + | k: integer; | |
| 21 | + | begin | |
| 22 | + | with Sender as TFindDialog do begin | |
| 23 | + | k := Pos(FindText, Memo1.Lines.Text); | |
| 24 | + | if k > 0 then begin | |
| 25 | + | Memo1.SelStart := k - 1; | |
| 26 | + | Memo1.SelLength := Length(FindText); | |
| 27 | + | end else | |
| 28 | + | Beep(); | |
| 29 | + | end; | |
| 30 | + | end; | |
| 31 | + | ``` | |
| 32 | + | ||
| 33 | + | Jos halutaan toistaa toimintoa useita kertoja samalla hakutekstillä, niin on muistettava viimeisin löydetty sijainti ja jatkettava hakua täältä - StrUtils-[[Unit/fi|käännösyksikön]] funktio `PosEx()` on täydellinen tähän tarkoitukseen: | |
| 34 | + | ||
| 35 | + | ``` pas | |
| 36 | + | uses | |
| 37 | + | StrUtils; | |
| 38 | + | ||
| 39 | + | type | |
| 40 | + | TForm1 = class(TForm) | |
| 41 | + | private | |
| 42 | + | FFoundPos: Integer; | |
| 43 | + | ... | |
| 44 | + | ||
| 45 | + | procedure TForm1.Button1Click(Sender: TObject); | |
| 46 | + | begin | |
| 47 | + | with FindDialog1 do | |
| 48 | + | begin | |
| 49 | + | if frEntireScope in Options then // Search begins at file start | |
| 50 | + | FFoundPos := 0 | |
| 51 | + | else | |
| 52 | + | FFoundPos := Memo1.SelStart; // Serach begins at current cursor position | |
| 53 | + | Execute; | |
| 54 | + | end; | |
| 55 | + | end; | |
| 56 | + | ||
| 57 | + | procedure TForm1.FindDialog1Find(Sender: TObject); | |
| 58 | + | begin | |
| 59 | + | with Sender as TFindDialog do | |
| 60 | + | begin | |
| 61 | + | FFoundPos := PosEx(FindText, Memo1.Lines.Text, FFoundPos+1); | |
| 62 | + | if FFoundPos > 0 then | |
| 63 | + | begin | |
| 64 | + | Memo1.SelStart := FFoundPos - 1; | |
| 65 | + | Memo1.SelLength := Length(FindText); | |
| 66 | + | end else | |
| 67 | + | Beep(); | |
| 68 | + | end; | |
| 69 | + | end; | |
| 70 | + | ``` | |
| 71 | + | ||
| 72 | + | ## Katso myös | |
| 73 | + | ||
| 74 | + | - [[doc:lcl/dialogs/tfinddialog.html|TFindDialog doc]] | |
| 75 | + | - [[TReplaceDialog/fi|TReplaceDialog]] | |
| 76 | + | ||
| 77 | + | --- | |
| 78 | + | *From the Free Pascal wiki, page "TFindDialog/fi", as it stood on 2019-10-13 after a change by Djzepi, 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).* |
