Forum > General

SynEdit and ReplaceDialog

(1/2) > >>

Sora-Kun:
Hello,
I'm making a python IDE, but i couldn't mix the  SynEdit1 with the ReplaceDialog1 so that it search and replace words. Can you help me please  :o ?
Thanks  ::)

theo:
This is just a very incomplete example, but should show you the way:


--- Quote ---procedure TForm1.Button2Click(Sender:TObject);
begin
  ReplaceDialog1.Execute;
end;

procedure TForm1.ReplaceDialog1Replace(Sender:TObject);
var
  rOptions:   TSynSearchOptions;
  sSearch:    String;
  sReplace:   String;
begin
    rOptions := [ssoPrompt,ssoReplace];
    sReplace:=ReplaceDialog1.ReplaceText;
    sSearch := ReplaceDialog1.FindText;
  if Length(sSearch) = 0 then
  begin
    Messagedlg('Enter Find Text', mtInformation, [mbOk], 0);
  end else
  begin
    if not (frDown in ReplaceDialog1.Options) then
      Include(rOptions, ssoBackwards);
    if frMatchCase in ReplaceDialog1.Options then
      Include(rOptions, ssoMatchCase);
    if frWholeWord in ReplaceDialog1.Options then
      Include(rOptions, ssoWholeWord);

    if Synedit1.SearchReplace(sSearch, sReplace, rOptions) = 0 then
    begin
      Beep;
      Messagedlg('Text "' + sSearch + '" not found!', mtInformation, [mbOk], 0);
    end;
  end;
end;


procedure TForm1.SynEdit1ReplaceText(Sender:TObject;const ASearch,AReplace:
  string;Line,Column:integer;var ReplaceAction:TSynReplaceAction);
begin
  if Messagedlg('Replace this occurence?', mtInformation, [mbOk,mbCancel], 0)=mrOK then
        ReplaceAction:=raReplace else ReplaceAction:=raSkip;
end;

--- End quote ---

juandelacruz:
theo,

Thanks for your reply.  I'm writing a notepad replacement to teach myself lazarus/free pascal and I'm having some problems with implementing search and replace.  Your reply gave me additional ideas on how to solve my problems.

Basically, my implementation was the same as yours except that instead of doing something like this:


--- Code: ---      Include(rOptions, ssoBackwards);

--- End code ---

I did it like this:


--- Code: ---    rOptions :=  rOptions + [ssoBackwards];

--- End code ---

Is there a difference in the two?  Reading up on sets in the Delphi Basics website and the Teach Yourself Borland Delphi 4 in 21 Days book, the two should have the same effect.  Or am I missing something?

Thanks for any reply.

theo:

--- Quote from: juandelacruz on June 01, 2010, 09:40:56 pm ---Or am I missing something?

--- End quote ---

It's functionally the same afaik.

juandelacruz:
Theo, thank you very much for your reply.  It rules that out as the source of my problem.  I guess I will just have to create a new topic about it.

Linkos, my apologies for hijacking your topic.  Good luck on your Python IDE project.

Navigation

[0] Message Index

[#] Next page

Go to full version