To wrap or not to wrap - that is the question!
Paraphrasing Shakepeare's Hamlet, I wonder what this parameter of t he Find method is all about:
- When starting a search for a word which exists multiple times in a document, and continue searching after t he last find in the document (at that moment of course I do not know that it is the last occurrence), I find find myself again in the first find...
- With my development FMfindRepl I have the same effect, even defining the parameter as 0.
- In the FM Find/Change dialog Wrapping can not be influenced.
FDK reference states:
FS_FindWrap A BoolT flag that determines whether the find operation will wrap when it reaches the location where the search began.
- Default is True; the find operations wraps.
- If False, after reaching the location where the search began, the find operation returns an empty
F_TextRangeT and FA_errno is set to FE_NotFound.
In FMfindReplace I have this defintion for the Find parameters:
oPropVal1 = new PropVal() ; /
oPropVal1.propIdent.num = Constants.FS_FindWrap ;
oPropVal1.propVal.valType = Constants.FT_Integer;
oPropVal1.propVal.ival = 0 ; // no wrap
findParms.push(oPropVal1);
But this obviously has no no effect.
There was ample discussion on this 10 years ago: Telling Find method NOT to wrap
Rick makes the proposal «Before each find, try setting the document's TextSelection property to the TextLoc you want to start the search from».
But I have no idea how to follow this advice, because the result of the find is a new text location...
So the question remains:
How to stop searching after the last find in a document?
Edit
The problem becomes cumbersome when searching in a book.
- If, for example, search term does not exist in the first document, a script gets the feedback "not found" and the second document can be searched (standard FM Find/Change opens the files hidden, hence you do not notice the processing of this file).
- In the second document the search term exists multiple times - you need to observe yourself that you have wrapped the search and need to close the document yourself.
- Then you can continue Search in Book and FM (in case of standard Search/Change) will continue in the third document. Assuming that there is only 1 occurrence of the search term, Repeatedly pressing the Find button will not advance to the next document
- ...
It will be darn difficult to make my script do the right thing: observe the end of the document and then go to the next one, if the user presses just Find, Find, ... until he finds the desired environment of his search term.

