I have now shrinked the script to the (what I think) bare minimum:
/* Test_GetFindParameters.jsx ====== UTF-8 ================================
Test for the functions GetFindParameters, FindSomething
History 2020-12-05 test with VSCode and ESDebugger
*/ ; // ==================================================================
//@target framemaker
var KLD_Z = KLD_Z || {}; // global script object
KLD_Z.GetFindParameters = function (sSearch) { //====
// Set up a text find with case sensitive RegEx
var bRegEx, findParms, qFlags, oPropVal1, oPropVal2, oPropVal3;
findParms = new PropVals();
oPropVal1 = new PropVal() ;
oPropVal1.propIdent.num = Constants.FS_FindText;
oPropVal1.propVal.valType = Constants.FT_String;
oPropVal1.propVal.sval = sSearch;
findParms.push(oPropVal1);
oPropVal2 = new PropVal() ;
oPropVal2.propIdent.num = Constants.FS_FindCustomizationFlags ;
oPropVal2.propVal.valType = Constants.FT_Integer;
qFlags = 0;
qFlags = qFlags | Constants.FF_FIND_CONSIDER_CASE; // 0x01
qFlags = qFlags | Constants.FF_FIND_USE_REGEX; // 0x10
oPropVal2.propVal.ival = qFlags; //
findParms.push(oPropVal2);
oPropVal3 = new PropVal ();
oPropVal3.propIdent.num = Constants.FS_RegexFlavour;
oPropVal3.propVal.valType = Constants.FT_Integer;
oPropVal3.propVal.ival = Constants.FR_USE_PERL; // 1
findParms.push(oPropVal3);
$.bp(true); // check oPropVal2 and oPropVal3
return findParms;
} //--- end GetFindParameters -------------------------------------------
KLD_Z.FindSomething = function (oDoc, iFS, iFV, sSearch, iMode, bWord, bCase, bBack, bStart) { // ========
// Find anything defined by the parameters
var oFindParms, oTR, oTRsaved ;
oTRsaved = oDoc.TextSelection; // we may need to come back to the start location
oTR = oDoc.TextSelection; // start from current location
oFindParms = KLD_Z.GetFindParameters (sSearch); // set up for text search, case sentive RegEx
oTR = oDoc.Find(oTR.beg, oFindParms);
if (FA_errno === Constants.FE_Success) { // 0: FE_Success; -95: FE_NotFound
return oTR;
} else { // Not found
return undefined;
}
} //--- end FindSomething -----------------------------------------------
KLD_Z.main = function () { // ============================================
// Find text containing 1stxxx 2ndxxx 3rdxxx or 4thxxx 5thxxx ...
var oDoc, OK, oTR;
//$.bp(true);
oDoc = app.ActiveDoc;
//OK = KLD_Z.FindSomething (oDoc, iFS, iFV, sSearch, iMode, bWord, bCase, bBack);
//$.bp(true);
oTR = KLD_Z.FindSomething (oDoc, 1, null, "\\d[st|nd|rd|th]", 2, false, false, false);
if (oTR == undefined) {
Alert ("not found");
}
} //--- end main ---------------------------------------------------------
KLD_Z.main ();
But I still get the same errors when lookink at the properties on the line " $.bp(true); // check oPropVal2 and oPropVal3".
Sorry folks, the whole issue is a Hornberger Schiessen (wild goose chase):
The error messages in the Data Browser are irrelevant for the positive result. The script successfully finds 1st, 2nd, 4th and 5th and refuses to find 3Rd - hence RegEx search is OK and Consider Case is observed:
/*Test_MiniFind.jsx ====== UTF-8 ==========================================
Test for the functions GetFindParameters, FindSomething
History 2020-12-09
*/ ; // ===================================================================
//#target framemaker
//@target framemaker
function GetFindParameters (sSearch) { //======================
// Set up a text find with case sensitive RegEx
var findParms, qFlags, oPropVal1, oPropVal2, oPropVal3;
findParms = new PropVals();
oPropVal1 = new PropVal() ;
oPropVal1.propIdent.num = Constants.FS_FindText;
oPropVal1.propVal.valType = Constants.FT_String;
oPropVal1.propVal.sval = sSearch;
findParms.push(oPropVal1);
oPropVal2 = new PropVal() ;
oPropVal2.propIdent.num = Constants.FS_FindCustomizationFlags ;
oPropVal2.propVal.valType = Constants.FT_Integer;
qFlags = 0;
qFlags = qFlags | Constants.FF_FIND_CONSIDER_CASE; // 0x01
qFlags = qFlags | Constants.FF_FIND_USE_REGEX; // 0x10
oPropVal2.propVal.ival = qFlags; //
findParms.push(oPropVal2);
oPropVal3 = new PropVal ();
oPropVal3.propIdent.num = Constants.FS_RegexFlavour;
oPropVal3.propVal.valType = Constants.FT_Integer;
oPropVal3.propVal.ival = Constants.FR_USE_PERL; // 1
findParms.push(oPropVal3);
//$.bp(true); // check oPropVal2 and oPropVal3 - ival reports errors...
return findParms;
} //--- end GetFindParameters -------------------------------------------------
function FindSomething (oDoc, sSearch) { // ===============================
var oFindParms, oTR, oTRsaved ;
oTRsaved = oDoc.TextSelection; // we may need to come back
oTR = oDoc.TextSelection; // start from current location
oFindParms = GetFindParameters (sSearch);
if (oFindParms === null) {return undefined;} // oTR has not changed yet
oTR = oDoc.Find(oTR.beg, oFindParms);
if (FA_errno === Constants.FE_Success) { // 0: FE_Success; -95: FE_NotFound
oDoc.TextSelection = oTR; // selection visible ?
oDoc.ScrollToText(oTR); // selection visible ? Yes
return oTR;
} else { // Not found
oDoc.TextSelection = oTRsaved;
oDoc.ScrollToText(oTRsaved);
return undefined;
}
} //--- end FindSomething ------------------------------------------------
function main () { // =====================================================
// testfile: E:\_DDDprojects\_JSX-library\TestFiles\Gugus-file1.fm
// ontains 1st, 2nd, 3Rd, 4th, 5th
var oDoc = app.ActiveDoc, OK, oTR;
oTR = FindSomething (oDoc, "\\d[st|nd|rd|th]"); // text by regex
if (oTR == undefined) {
Alert ("not found");
}
} //--- end main ----------------------------------------------------------
main ();
I do not know yet why my initial script did not work - have to take a very close look to the differences to this working script.