tags:

views:

139

answers:

2

Hello,

For some reason, using

   SearchText := 'Program Files';
   ReplaceText := 'Program Files (x86)';
   SearchAndReplace(SearchText, ReplaceText);

Would do absolutely nothing, it just won't change text, works fine when using any other text.

Is this some sort of "Reserve" word? Or ( ) is what makes it do not work?

procedure Tfc_Great.SearchAndReplace
           (InSearch, InReplace: string) ;
var X, ToEnd : integer;
    oldCursor : TCursor;
begin
   oldCursor := Screen.Cursor;
   Screen.Cursor := crHourglass;
   with RichEdit1 do
   begin
     X := 0;
     ToEnd := length(Text) ;
     X := FindText(inSearch, X, ToEnd, []) ;
     while X <> -1 do
     begin
       SetFocus;
       SelStart := X;
       SelLength := length(inSearch) ;
       SelText := InReplace;
       X := FindText(inSearch,
                     X + length(InReplace),
                     ToEnd, []) ;
     end;
   end;
   Screen.Cursor := oldCursor;
end;
+1  A: 

Try to assign the output ;)

SearchText := 'Program Files';
ReplaceText := 'Program Files (x86)';
ResultText := SearchAndReplace(Text, SearchText, ReplaceText);

with

function SearchAndReplace
   (sSrc, sLookFor, sReplaceWith : string) : string;
var
   nPos, nLenLookFor : integer;
begin
   nPos := Pos(sLookFor, sSrc) ;
   nLenLookFor := Length(sLookFor) ;
   while (nPos > 0) do begin
     Delete(sSrc, nPos, nLenLookFor) ;
     Insert(sReplaceWith, sSrc, nPos) ;
     nPos := Pos(sLookFor, sSrc) ;
   end;
   Result := sSrc;
end;
Scoregraphic
I am usingRichEdit.Lines.SaveToFile(mfp, TEncoding.ASCII);
Tom
RichEdit.Lines.LoadFromFile(mfp, TEncoding.ASCII);
Tom
What's in RichEdit? The text you want to replace? What's in mfp?
Scoregraphic
A: 

Solved, was conditions issue

Tom