Der er ellers et udemærket eksempel i Delphi's hjælp.
This example requires a TRichEdit, a TButton, and a TFindDialog. Clicking the button click will display a Find Dialog to the right of the edit control. Filling in the "Find what" text and pressing the Find Next button will select the first matching string in the Rich Edit control that follows the previous selection.
procedure TForm1.Button1Click(Sender: TObject);
begin FindDialog1.Position := Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top); FindDialog1.Execute; end;
procedure TForm1.FindDialog1Find(Sender: TObject); var FoundAt: LongInt; StartPos, ToEnd: Integer; begin with RichEdit1 do begin { begin the search after the current selection if there is one } { otherwise, begin at the start of the text } if SelLength <> 0 then
StartPos := SelStart + SelLength else
StartPos := 0;
{ ToEnd is the length from StartPos to the end of the text in the rich edit control }
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]); if FoundAt <> -1 then begin SetFocus; SelStart := FoundAt; SelLength := Length(FindDialog1.FindText); end; end; end;
Jeg har lige lagt søgning bagud med, og Match-case. Fx som:
var findOptions: TSynSearchOptions;
procedure TForm1.FindDialog1Find(Sender: TObject); var FindText:string; begin FindText:=FindDialog1.FindText; if not (frDown in FindDialog1.Options) then include(findOptions,ssoBackwards); if frMatchCase in FindDialog1.Options then include(findOptions,ssoMatchCase); SynEdit1.SearchReplace(FindText,'',findOptions); end;
procedure TForm1.Button1Click(Sender: TObject); begin findOptions:=[]; FindDialog1.Execute; end;
procedure TForm1.FindDialog1Find(Sender: TObject); var FindText:string; begin FindText:=FindDialog1.FindText; if not (frDown in FindDialog1.Options) then include(findOptions,ssoBackwards); if frMatchCase in FindDialog1.Options then include(findOptions,ssoMatchCase); SynEdit1.SearchReplace(FindText,'',findOptions); end;
procedure TForm1.ToolButton70Click(Sender: TObject); begin findOptions:=[]; FindDialog1.Execute;
end;
også en procedure FindDialog1Find(Sender: TObject); under 'var' i toppen
Har du 2 procedurer der hedder FindDialog1Find? Du skal jo have koden fra den FindDialog1Find jeg viste, i den procedure der kaldes ved eventen Find på din FindDialog
Det er en start, men du skal stadig sætte eventen. Vælg din FindDialog, og se under Events i Object Inspector. Ud for OnFind eventen skal du vælge FindDialog1Find. Så burde det virke.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.