mikakoistinen
6 years agoContributor
Script extension method parameter
Hi,
I tried to make my 1st script extension.
function cleanStr(s) { s = aqString.Replace(s, chr(27), ''); s = aqString.Replace(s,chr(2), ''); s = aqString.Replace(s,chr(28), ''); s = aqString.Replace(s,chr(14), ''); return s; }
same code works okay if used directly in jscript, but if it is extension I get error Value must be an object (or similar, error is in native language)
i call it like (skjstrutils is the extension )
showmessage(skjstrutils.cleanStr('aaaaa'));
The error message is a bit misleading. The problem is not with the parameter, it's with your use of the chr method. That method is a method provided within the TestComplete environment and is not available within script extensions.
To do what you want to do, use the native JScript method String.fromCharCode like so
function cleanStr(s) { s = aqString.Replace(s, String.fromCharCode(27), ''); s = aqString.Replace(s,String.fromCharCode(2), ''); s = aqString.Replace(s,String.fromCharCode(28), ''); s = aqString.Replace(s,String.fromCharCode(14), ''); return s; }