Witam,
Proszę o pomoc w realizacji zadania wyszukiwania i zamiany tekstu w SynEdicie. Niestety nie jestem w stanie rozszyfrować dwóch demonstracyjnych programów...Póki co mam tak:
procedure TForm1.FormCreate(Sender: TObject);
begin
SynEdit.SearchEngine := TSynEditSearch.Create( SynEdit );
end;
następnie w zdarzeniu OnFind:
procedure TForm1.FindDialog1Find(Sender: TObject);
var
rOptions: TSynSearchOptions;
dlg: TFindDialog;
sSearch: string;
begin
if Sender = ReplaceDialog1 then
dlg := ReplaceDialog1
else
dlg := FindDialog1;
sSearch := dlg.FindText;
if Length(sSearch) = 0 then begin
Beep;
showMessage( 'Can''t search for empty text!');
end else begin
rOptions := [];
if not (frDown in dlg.Options) then
Include(rOptions, ssoBackwards);
if frMatchCase in dlg.Options then
Include(rOptions, ssoMatchCase);
if frWholeWord in dlg.Options then
Include(rOptions, ssoWholeWord);
if SynEdit.SearchReplace(sSearch, '', rOptions) = 0 then begin
Beep;
ShowMessage('SearchText ''' + sSearch + ''' not found!');
end
end;
end;
Niestety ciągle dostaje opcje, że tekst nie odnaleziono..
ok wystarczy dodać jeszcze:
procedure TForm1.ReplaceDialog1Find(Sender: TObject);
var
rOptions: TSynSearchOptions;
dlg: TFindDialog;
sSearch: string;
begin
if Sender = ReplaceDialog1 then
dlg := ReplaceDialog1
else
dlg := FindDialog1;
sSearch := dlg.FindText;
if Length(sSearch) = 0 then begin
Beep;
ShowMessage('Can''t search for empty text!');
end else begin
rOptions := [];
if not (frDown in dlg.Options) then
Include(rOptions, ssoBackwards);
if frMatchCase in dlg.Options then
Include(rOptions, ssoMatchCase);
if frWholeWord in dlg.Options then
Include(rOptions, ssoWholeWord);
if SynEdit.SearchReplace(sSearch, '', rOptions) = 0 then begin
Beep;
ShowMessage('SearchText ''' + sSearch + ''' not found!');
end else
// lblSearchResult.Visible := FALSE;
end;
end;
oraz to:
procedure TForm1.ReplaceDialog1Replace(Sender: TObject);
var
rOptions: TSynSearchOptions;
sSearch: string;
begin
sSearch := ReplaceDialog1.FindText;
if Length(sSearch) = 0 then begin
Beep;
ShowMessage('Can''t replace an empty text!');
// lblSearchResult.Visible := TRUE;
end else begin
rOptions := [ssoReplace];
if frMatchCase in ReplaceDialog1.Options then
Include(rOptions, ssoMatchCase);
if frWholeWord in ReplaceDialog1.Options then
Include(rOptions, ssoWholeWord);
if frReplaceAll in ReplaceDialog1.Options then
Include(rOptions, ssoReplaceAll);
if SynEdit.SearchReplace(sSearch, ReplaceDialog1.ReplaceText, rOptions) = 0
then begin
Beep;
ShowMessage('SearchText ''' + sSearch +
''' could not be replaced!');
// lblSearchResult.Visible := TRUE;
end else
// lblSearchResult.Visible := FALSE;
end;
end;
I DZIAŁA! Temat do zamknięcia może komuś się przyda. Przepraszam moderatorów.