View Issue Details

IDProjectCategoryView StatusLast Update
0002508JEDI VCL00 JVCL Componentspublic2005-08-10 08:14
ReporterSimesAssigned Toobones 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.00 BETA 2 
Target VersionFixed in Version3.10 
Summary0002508: TJvFindReplace incorrectly reports number replaced when Whole Word or Match Case options in effect
DescriptionRun the code below. Select Replace All. Dialog reports 6 occurences replaced, when it's really replaced only 1.
Additional Informationunit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, JvComponent, JvFindReplace;

type
  TForm1 = class(TForm)
    JvFindReplace1: TJvFindReplace;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin
  Button1.Caption := 'Reset';
  Button2.Caption := 'Test';
  Button1Click(self);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Clear;
  Memo1.Lines.Add('unit main frm;');
  Memo1.Lines.Add('main this main that maintain main');
  Memo1.Lines.Add('a main b');
  Memo1.CaretPos := Point(0, 0);
  Memo1.SetFocus;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  JvFindReplace1.Options := [frDown, frWholeWord];
  JvFindReplace1.EditControl := Memo1;
  JvFindReplace1.FindText := 'main';
  JvFindReplace1.ReplaceText := 'abcd';
  JvFindReplace1.Replace;
end;

end.
TagsNo tags attached.

Relationships

related to 0002515 resolvedobones Modified TJvFindReplace source to correct issues 2503, 2504, 2513 

Activities

Simes

2005-01-16 01:15

reporter   ~0006148

suggested change. Move the increment down a bit.

procedure TJvFindReplace.ReplaceAll(const SearchText, ReplaceText: string);
var
  Txt: string;
  FoundPos: TFoundText;
  TmpOptions: TFindOptions;
  SLen, RLen, TLen: Integer;
  Terminate: Boolean;
begin
  if not Assigned(FEditControl) then
    Error;
  Terminate := False;
  UpdateDialogs;
  TmpOptions := FReplaceDialog.Options;
  Txt := FEditControl.Text;
  SLen := Length(SearchText);
  RLen := Length(ReplaceText);
  TLen := Length(Txt);
  FoundPos := FindInText(Txt, SearchText, EditControl.SelStart + EditControl.SelLength, TLen, True);

  if FoundPos.StartAt > -1 then begin
    FNumberReplaced := 0;
    DoReplacingAll;
    while FoundPos.StartAt > -1 do begin

      Inc(FNumberReplaced); // this line needs to be moved down a bit...

      if (frWholeWord in TmpOptions) and not FoundPos.isWhole then begin
        FoundPos := FindInText(Txt, SearchText, FoundPos.StartAt + RLen + 1, TLen + (RLen - SLen), True);
        Continue;
      end;
      if (frMatchCase in TmpOptions) and not FoundPos.isSameCase then begin
        FoundPos := FindInText(Txt, SearchText, FoundPos.StartAt + RLen + 1, TLen + (RLen - SLen), True);
        Continue;
      end;

// ...to here ---->

      Delete(Txt, FoundPos.StartAt + 1, SLen);
      Insert(ReplaceText, Txt, FoundPos.StartAt + 1);
      FoundPos := FindInText(Txt, SearchText, FoundPos.StartAt + RLen + 1, TLen + (RLen - SLen), True);
      if FoundPos.StartAt mod 60 = 0 then begin
        DoProgress(FoundPos.StartAt, Terminate);
        if Terminate then
          Exit;
      end;
    end;
    FEditControl.Text := Txt;
    DoReplacedAll(FReplaceDialog);
  end else
    DoFailed(FReplaceDialog);
end;

Simes

2005-01-16 13:05

reporter   ~0006159

See 2515 - it has a modified version of this component.

Issue History

Date Modified Username Field Change
2005-01-16 01:14 Simes New Issue
2005-01-16 01:15 Simes Note Added: 0006148
2005-01-16 13:05 Simes Note Added: 0006159
2005-01-17 03:15 obones Relationship added related to 0002515
2005-08-10 08:14 obones Status new => resolved
2005-08-10 08:14 obones Resolution open => fixed
2005-08-10 08:14 obones Assigned To => obones