Recent

Author Topic: SynEdit and ReplaceDialog  (Read 8034 times)

Sora-Kun

  • Full Member
  • ***
  • Posts: 162
  • I can smell your presence ...
    • Sora-Kun
SynEdit and ReplaceDialog
« on: June 01, 2010, 10:58:34 am »
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  ::)
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.

Made in Lazarus.
Soon, in The WWW.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1932
Re: SynEdit and ReplaceDialog
« Reply #1 on: June 01, 2010, 01:02:37 pm »
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;

juandelacruz

  • New Member
  • *
  • Posts: 17
Re: SynEdit and ReplaceDialog
« Reply #2 on: June 01, 2010, 09:40:56 pm »
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: [Select]
      Include(rOptions, ssoBackwards);

I did it like this:

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

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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1932
Re: SynEdit and ReplaceDialog
« Reply #3 on: June 02, 2010, 03:02:06 am »
Or am I missing something?

It's functionally the same afaik.

juandelacruz

  • New Member
  • *
  • Posts: 17
Re: SynEdit and ReplaceDialog
« Reply #4 on: June 02, 2010, 04:04:46 am »
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.

Sora-Kun

  • Full Member
  • ***
  • Posts: 162
  • I can smell your presence ...
    • Sora-Kun
Re: SynEdit and ReplaceDialog
« Reply #5 on: June 07, 2010, 08:16:03 am »
hey man ! no probleme =) and thanks every body for your help  :D
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.

Made in Lazarus.
Soon, in The WWW.

 

TinyPortal © 2005-2018