Board index » delphi » Problem with Word97 call using COM to find and replace strings using wildcards

Problem with Word97 call using COM to find and replace strings using wildcards

Hi,

I have the following problem. I want to do a find and replace in Word from
my Delphi app...  This is working fine except when I try to use wildcards!
So a find on 'Hello' works but when I want to find '<Hello>' a 'bad
parameter' error is given. This is because '<' and '>' are wildcards.  From
VBA and in Word the '<' and '>' characters need to be proceeded by a '\' to
mark them as a normal character. But this doesn't seem to work from Delphi.
'\<Hello\>' therefore also gives a 'bad parameter' error.

Are there other escape characters I should use instead or in combination
with '\' ?

If anyone could tell me...  Please do.

Ronald de Waal.

Sample code.

  FindTextOleVar             := 'Hello';  // Works
  FindTextOleVar             := '<Hello>';   // Doesn't work
  FindTextOleVar             := '\<Hello\>';  // Doesn't work

  ReplaceWithOleVar       := 'World'

  MatchCaseOleVar         := false;
  MatchWholeWordOleVar    := false;
  MatchWildcardsOleVar    := true;
  MatchSoundsLikeOleVar   := false;
  MatchAllWordFormsOleVar := false;
  ForwardOleVar           := true;
  WrapOleVar              := wdFindContinue;
  FormatOleVar            := false;
  ReplaceOleVar           := wdReplaceAll;

  FWordApp.Selection.Range.Find.Execute(FindTextOleVar,
                                        MatchCaseOleVar,
                                        MatchWholeWordOleVar,
                                        MatchWildcardsOleVar,
                                        MatchSoundsLikeOleVar,
                                        MatchAllWordFormsOleVar,
                                        ForwardOleVar,
                                        WrapOleVar,
                                        FormatOleVar,
                                        ReplaceWithOleVar,
                                        ReplaceOleVar);

 

Re:Problem with Word97 call using COM to find and replace strings using wildcards


Sorry for the question.....

I seemed to have mixed up when determining the string to look for before
running this part. Did show correctly was probably typecasted wrong !

Problem solved...

Ronald..

Re:Problem with Word97 call using COM to find and replace strings using wildcards


<<Ronald de Waal:
 So a find on 'Hello' works but when I want to find '<Hello>'
a 'bad parameter' error is given. This is because '<' and '>'
are wildcards.  From VBA and in Word the '<' and '>'
characters need to be proceeded by a '\' to mark them as a
normal character. But this doesn't seem to work from Delphi.
'\<Hello\>' therefore also gives a 'bad parameter' error.

Quote

I'm mystified by this - it works perfectly well on my system
(Word 97 SR1, Delphi 4.03). I can't see anything wrong
with your code, either. Are you sure you haven't just
got a typo somewhere?

Deborah Pate

Other Threads