TFindDialog/fi
English · Français · Suomi · Русский · 中文(中国)
TFindDialog
on komponentti, joka auttaa tiedon etsinnässä. Se löytyy komponenttipaletin 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() funktiota. Luo OnFind-metodi, jossa itse haku suoritetaan.

Käyttö
Seuraavat esimerkit kuvaavat TFindDialog-sovelluksen käyttöä muistioon (TMemo) tallennetun tietyn lauseen etsimiseen.
procedure TForm1.Button1Click(Sender: TObject);
begin
FindDialog1.Execute();
end;
procedure TForm1.FindDialog1Find(Sender: TObject);
var
k: integer;
begin
with Sender as TFindDialog do begin
k := Pos(FindText, Memo1.Lines.Text);
if k > 0 then begin
Memo1.SelStart := k - 1;
Memo1.SelLength := Length(FindText);
end else
Beep();
end;
end;Jos halutaan toistaa toimintoa useita kertoja samalla hakutekstillä, niin on muistettava viimeisin löydetty sijainti ja jatkettava hakua täältä - StrUtils-käännösyksikön funktio PosEx() on täydellinen tähän tarkoitukseen:
uses
StrUtils;
type
TForm1 = class(TForm)
private
FFoundPos: Integer;
...
procedure TForm1.Button1Click(Sender: TObject);
begin
with FindDialog1 do
begin
if frEntireScope in Options then // Search begins at file start
FFoundPos := 0
else
FFoundPos := Memo1.SelStart; // Serach begins at current cursor position
Execute;
end;
end;
procedure TForm1.FindDialog1Find(Sender: TObject);
begin
with Sender as TFindDialog do
begin
FFoundPos := PosEx(FindText, Memo1.Lines.Text, FFoundPos+1);
if FFoundPos > 0 then
begin
Memo1.SelStart := FFoundPos - 1;
Memo1.SelLength := Length(FindText);
end else
Beep();
end;
end;Katso myös
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.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
