Find & Replace lazarus / 10-Designer ---------------------------------------------------------------------- Giorgio · 2005-07-13 14:29 Hi all, excuse me if it may be a newbye question: I'm trying to add find and find&replace to a SynEdit. I've Googled a while and it seem that SearchReplace should do the job, but examples I found on Delphi newsgroup doesn't seem to work in Lazarus, and in the thousands lines of Lazarus editor sourcecode I'm not able to find an example of that, at least not a simple example to understand ad adapt to my very basic "find & replace" need; I also missed to find example code online that exemplify how to do it with Lazarus. Could someone kindly link or paste here some examples? Thanks a lot! ---------------------------------------------------------------------- RudieD · 2005-07-18 18:06 Hi Giorgio, I've added the following to my form (Hope this helps !): NB: You have to add the Lazarus path to your projects search path and findreplacedialog to your uses clause !   TfrmMain = class(TForm)   private     { private declarations }     FFindReplaceDialog: TLazFindReplaceDialog;     procedure DoFindReplace(Replace:boolean;Again:boolean=False);     procedure FindAgain;   public     { public declarations }     function FindReplaceDialog:TLazFindReplaceDialog;   end; ... procedure TfrmMain.DoFindReplace(Replace:boolean;Again:boolean=False); var OldCaretXY:TPoint;   AText,ACaption:AnsiString;   TopLine,ALeft,ATop: integer; begin   if Replace then     FindReplaceDialog.Options :=       FindReplaceDialog.Options + [ssoReplace, ssoReplaceAll, ssoPrompt]   else     FindReplaceDialog.Options :=       FindReplaceDialog.Options - [ssoReplace, ssoReplaceAll, ssoPrompt];   if not Again then   begin     FindReplaceDialog.ShowModal;     if FindReplaceDialog.ModalResult = mrCancel then       Exit;     with FindReplaceDialog.TextToFindComboBox do     begin       if (Text = '') and (ItemIndex > -1) then         Text := Items[ItemIndex]       else         Text := Text;         FindReplaceDialog.FindText := Text;       if Text <> '' then       begin         if Items.IndexOf(Text) > 0 then           Items.Move(Items.IndexOf(Text),0)         else           Items.Insert(0,Text);       end;     end;   end;   OldCaretXY:=SynEdit1.CaretXY;   if SynEdit1.SelAvail then begin     if ssoBackwards in FindReplaceDialog.Options then       SynEdit1.LogicalCaretXY:=SynEdit1.BlockBegin     else       SynEdit1.LogicalCaretXY:=SynEdit1.BlockEnd   end;   try     SynEdit1.SearchReplace(       FindReplaceDialog.FindText,FindReplaceDialog.ReplaceText,FindRep laceDialog.Options);   except     on E: ERegExpr do begin       MessageDlg(lisUEErrorInRegularExpression,         E.Message,mtError,[mbCancel],0);       exit;     end;   end;   if (OldCaretXY.X=SynEdit1.CaretX)   and (OldCaretXY.Y=SynEdit1.CaretY)   and not (ssoReplaceAll in FindReplaceDialog.Options) then begin     ACaption:=lisUENotFound;     AText:=Format(lisUESearchStringNotFound, [FindReplaceDialog.FindText]);     MessageDlg(ACaption,AText,mtInformation,[mbOk],0);   end else begin     TopLine := SynEdit1.CaretY - (SynEdit1.LinesInWindow div 2);     if TopLine < 1 then TopLine:=1;     SynEdit1.TopLine := TopLine;   end; end; procedure TfrmMain.FindAgain; var OldOptions: TSynSearchOptions; begin   OldOptions:=[];   OldOptions:=FindReplaceDialog.Options;   if ssoEntireScope in OldOptions then     FindReplaceDlg.Options:=FindReplaceDialog.Options-[ssoEntireScope];   DoFindReplace(False,True);   FindReplaceDialog.Options:=OldOptions; End; function TfrmMain.FindReplaceDialog: TLazFindReplaceDialog; begin   if not assigned(FFindReplaceDialog) then   begin     FFindReplaceDialog := TLazFindReplaceDialog.Create(Self);     FFindReplaceDialog.Position := poOwnerFormCenter;   end;   Result := FFindReplaceDialog; end; ---------------------------------------------------------------------- Giorgio · 2005-07-19 06:23 Quote from: "RudieD"Hi Giorgio, I've added the following to my form (Hope this helps !): Hi, I'll try it. For the moment, many thanks for the response!