WPCubed Product Support

How to use the Finder in WpTools?

Hello All,

I have tried to make a search form i Delphi XE8 with TWpRichText.Finder - but I cant get it to work. It seems that it jumps over some instances of found text in the TWPRicText document! I have tried several times to get it to work - but I can't figure it out :-( Can you help me?

My aim is to make a searchform that can find and select every instances of the searchtext - one at a time. But how to do this?

Thanks in advance.

Michael

unit fmSearchWpU;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.StdCtrls, Vcl.ExtCtrls, System.Actions, Vcl.ActnList,
  WPRTEDefs, WPCTRMemo, WPCTRRich, stdProc;

type
  TfmSearchWp = class(TForm)
    emcxLabel1: TLabel;
    teTextToFind: TEdit;
    rgSearchDirection: TRadioGroup;
    emcxButton1: TButton;
    ActionList1: TActionList;
    actSearch: TAction;
    procedure actSearchExecute(Sender: TObject);
  private
    { Private declarations }
    FWp: TWPRichText;
  public
    { Public declarations }
    class procedure ShowSearchWp(AWPRichText: TWPRichText; ACaption: String);
  end;

var
  fmSearchWp: TfmSearchWp;

implementation

{$R *.dfm}

{ TfmSearchWp }

procedure TfmSearchWp.actSearchExecute(Sender: TObject);
begin
  with FWp.Finder do begin
//    if rgSearchDirection.ItemIndex = 0 then
//      ToEnd
//    else
//      ToStart;
    while true do begin
      if rgSearchDirection.ItemIndex = 0 then begin
        if not prev(teTextToFind.Text) then break;
        SelectText;
        FWp.ScrollToPosition(FWp.CPPosition, 0, 10);
      end else begin
        if not Next(teTextToFind.Text) then break;
        SelectText;
        FWp.ScrollToPosition(FWp.CPPosition, 0, 10);
      end;
    end;
  end;
end;

class procedure TfmSearchWp.ShowSearchWp(AWPRichText: TWPRichText;
  ACaption: String);
begin
  Application.CreateForm(TfmSearchWp, fmSearchWp);
  try
    fmSearchWp.FWp := AWPRichText;
    fmSearchWp.FWp.CPPosition := 0;
    fmSearchWp.Caption := ACaption;
    fmSearchWp.ShowModal;
  finally
    FreeAndNil(fmSearchWp);
  end;
end;

end.
#1 ♥ 0
6k Views 1 links 2 users read 3 min
wpsupport

The finder works well, there is also an extensive find dialog which may be a good example on how to use it.

However: My aim is to make a searchform that can find and select every instances of the searchtext - one at a time. But how to do this?

**

This cannot really work since it is not possible to have a selection for several words on different paragraphs.

You can check out the unit

WPSyntaxHighlight

It may be of use.

This code is problematic:

  1. SelectText;
  2. [](http://www.wpcubed.com/forum/board/index.php?thread/7235-how-to-use-the-finder-in-wptools/#codeLine_47_f726f4) FWp.ScrollToPosition(FWp.CPPosition, 0, 10);

You should also set the CPPosition to Finder.FoundPostion.

#2 ♥ 0

Hello,

I have now set the CPPosition to Finder.FoundPosition - but it seems that the Finder only is able to find the first and last occurence of the searchstring. So how can I get to work so I can jump through all occurances of the searchstring?

Thanks in advance for any kind of help.

Michael Eriksen

#3 ♥ 0
wpsupport

You can only find occurrences one by one.

You can use the find dialog to verify that.

#4 ♥ 0
This category is archived. No new posts are possible.