Sign in Join
Wiki copytemporary

TFindDialog/fi: 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) 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.
22
3-<figure>
4-<img src="component-TFindDialog.png" title="component-TFindDialog.png" />
5-<figcaption>component-TFindDialog.png</figcaption>
6-</figure>
3+![](/wiki-images/3/33/Component-TFindDialog.png)
74
85## Käyttö
96
107Seuraavat esimerkit kuvaavat TFindDialog-sovelluksen käyttöä muistioon ([[TMemo/fi|TMemo]]) tallennetun tietyn lauseen etsimiseen.
118
129``` pas
1310procedure TForm1.Button1Click(Sender: TObject);
1411begin
1512 FindDialog1.Execute();
1613end;
1714
1815procedure TForm1.FindDialog1Find(Sender: TObject);
1916var
2017 k: integer;
2118begin
2219 with Sender as TFindDialog do begin
2320 k := Pos(FindText, Memo1.Lines.Text);
2421 if k > 0 then begin
2522 Memo1.SelStart := k - 1;
2623 Memo1.SelLength := Length(FindText);
2724 end else
2825 Beep();
2926 end;
3027end;
3128```
3229
3330Jos 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:
3431
3532``` pas
3633uses
3734 StrUtils;
3835
3936type
4037 TForm1 = class(TForm)
4138 private
4239 FFoundPos: Integer;
4340 ...
4441
4542procedure TForm1.Button1Click(Sender: TObject);
4643begin
4744 with FindDialog1 do
4845 begin
4946 if frEntireScope in Options then // Search begins at file start
5047 FFoundPos := 0
5148 else
5249 FFoundPos := Memo1.SelStart; // Serach begins at current cursor position
5350 Execute;
5451 end;
5552end;
5653
5754procedure TForm1.FindDialog1Find(Sender: TObject);
5855begin
5956 with Sender as TFindDialog do
6057 begin
6158 FFoundPos := PosEx(FindText, Memo1.Lines.Text, FFoundPos+1);
6259 if FFoundPos > 0 then
6360 begin
6461 Memo1.SelStart := FFoundPos - 1;
6562 Memo1.SelLength := Length(FindText);
6663 end else
6764 Beep();
6865 end;
6966end;
7067```
7168
7269## Katso myös
7370
7471- [[doc:lcl/dialogs/tfinddialog.html|TFindDialog doc]]
7572- [[TReplaceDialog/fi|TReplaceDialog]]
7673
7774---
7875*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).*

Back to history