In this short newsletter, we are going to show you how to add spell checking capabilities to your TX Text Control application, using the popular ActiveX spell checker, Wintertree WSpell
To use this sample, you need to have both of the following components (trial or full versions) installed on your PC:
- TX Text Control ActiveX (any edition)
- WSpell Spelling Checker ActiveX
You can download the free TX Text Control trial version from:
The following sample is written for Visual Basic 6. It is however not difficult to make a few changes to get it working in Delphi or Internet Explorer, as our sample code has only been slightly modified from the shipped sample application from Wintertree.
The WSpell custom dialog uses a TextBox control, which can simply be replaced by TX Text Control. Having done that, there are only a few lines of code that need to be altered. The ReplaceWord callback method is called when WSpell wants to replace a misspelled word with a corrected one.
WSpell can only check raw text without formatting, we therefore need to be sure that the attributes of the replaced words are preserved. We do this with the following code:
Private Sub WSpell1_ReplaceWord()
Dim Start As Long
Start = WSpell1.WordOffset
' Replace the misspelt word. Keep first character to preserve formatting
TextControl.SelStart = WSpell1.WordOffset + 1
TextControl.SelLength = Len(WSpell1.MisspelledWord) - 1
TextControl.SelText = WSpell1.ReplacementWord
' Now delete first character
TextControl.SelStart = Start
TextControl.SelLength = 1
TextControl.SelText = ""
End Sub
First of all, the the starting position of the misspelled word in the text is saved to a variable. Secondly, the word is selected in TXTextControl, but the first letter of the word is skipped. Thirdly, the selection is replaced with the new word. Finally, the first letter, which had been skipped, gets deleted.
UPDATE (July 24, 2003): The folks at Wintree Software have kindly posted a page describing the integration of WSpell in TX Text Control.
We wish you a lot of success with this sample application. As always, we are delighted to help you with any matter relating to TX Text Control. Call us or e-mail us! Full contact details at:
Best regards
The Newsletter Team