Pages

Tuesday, February 26, 2008

Spell checking from AX

The AX class SysSpellChecker is a wrapper for the spellchecker of Word. Using this class you can offer spellchecking from AX.

Here is some sample code, checking text from a form string control:

SysSpellChecker spellChecker = SysSpellChecker::newCurrentLanguage();
TextBuffer textBuffer = new TextBuffer();
int wordStart;
int startSeparator;
int endSeparator;
str wordToCheck;
List spellingSuggestions;
ListEnumerator listEnumerator;
;
super();
startLengthyOperation();
setPrefix("Spell check");
textBuffer.setText(stringEdit.text());
startSeparator = 1;

while (startSeparator)
{
wordStart = textBuffer.find('[^ \n\t\\<\\>\\!\\\'\\\\\\#\\¤\\%\\&\\/\\(\\)\\=\\?\\,\\.\\:\\;\\*\\}\\{\\]', startSeparator) ? textBuffer.matchPos():0;

if (!wordStart)
break;

endSeparator = textBuffer.find('[ \n\t\\<\\>\\!\\\'\\\\\\#\\¤\\%\\&\\/\\(\\)\\=\\?\\,\\.\\:\\;\\*\\}\\{\\]', wordStart)? textBuffer.matchPos():0;

wordToCheck = textBuffer.subStr(wordStart, (endseparator ? endseparator : textBuffer.size()+1) - wordStart);

if (spellChecker.checkSpelling(wordToCheck) == false)
{
warning (strfmt("@SYS84009", wordToCheck));
spellingSuggestions = spellChecker.getSpellingSuggestions(wordToCheck);
listEnumerator = spellingSuggestions.getEnumerator();

while (listEnumerator.moveNext())
{
info (strFmt("Suggestion: %1", listEnumerator.current()));
}
}
startSeparator = endSeparator;
}

spellChecker.finalize();

info ("Spell check done");

endLengthyOperation();

Unfortunately there is a bug in the checkSpelling method of the COM object from Word, so it will always use the default language of your Office setup as the language to check your text against. So you can't spellcheck for other languages than your default language of Office. You can change the default language from the Office Tools however.

Monday, February 25, 2008

What to do if Virtual PC won’t restore its windows

This may be slightly off topic, but I'm sure we will receive more and more VPC images from MS for miscellaneous AX setups in the future.

I have had this problem a few times, especially when working with two monitors. All of sudden Virtual PC just will not restore its windows. You can start the program, but can't work with it.

The cause is that VPC somehow stores totally weird values for where to open the windows. So when you try to open the windows they kind of do open, but with coordinates that is nowhere near your own neighborhood.

The solution is to edit the options.xml file located in the %appdata%\Microsoft\Virtual PC folder. In the <window> <console> section, you should change the values for <left_position> and <top_position>, for example to 10, 10 which would place the window in the top left corner of your screen.