Support for spell checking in rich text controls

New properties for spell checking support

The SelectedStartPos and SelectedTextLength properties allow you to use a supported ActiveX control to spell check text in PowerBuilder rich text controls. Supported spell-checking controls include VSSpell from ComponentOne and WSpell from Wintertree Software.

The SelectedStartPos and SelectedTextLength properties take long datatype values. Property values must be set in a script at runtime.

The following code in the ReplaceWord event for a supported ActiveX spell-checking control sets the starting position in the text string that is being spell checked to the offset position of a misspelled word. After setting the starting position, the SelectedTextLength setting causes the entire misspelled word to be highlighted, and the ReplaceText call replaces the misspelled word with a word that the user selects in an ActiveX spell-checking control dialog box.

string str
str = ole_1.object.MisspelledWord
rte_1.SelectedStartPos = ole_1.object.WordOffset 
rte_1.SelectedTextLength  = Len(str)
rte_1.ReplaceText(ole_1.object.ReplacementWord)

For more information about these new properties, see SelectedStartPos and SelectedTextLength in the online Help.

Using an ActiveX spell-checking control

You use the SelectedStartPos and SelectedTextLength properties of the RichTextEdit control to highlight the current position of a misspelled word in a text string that you are parsing with a supported ActiveX spell-checking control. The following procedure uses an ActiveX control to spell check the entire text of the current band of a RichTextEdit control.

StepsTo spell check selected text in a RichTextEdit control:

  1. On a window with a RichTextEdit control, select Insert>Control>OLE from the window menu.

  2. Click the Insert Control tab of the Insert Object dialog box, select the installed ActiveX spell-checking control, and click OK.

  3. Click inside the window in the Window painter to insert the ActiveX control.

    By default, the name of the inserted control is ole_n, where n = 1 when there are no other OLE controls on the window.

  4. Add a menu item to a menu that you associate with the current window and change its Text label to Check Spelling.

  5. Add the following code to the Clicked event of the menu item, where windowName is the name of the window containing the RichTextEdit and ActiveX controls:

    string ls_selected
    
    //get the current band context, 
    
    //and leave select mode
    
    windowName.rte_1.selecttext(0,0,0,0)
    
    windowName.rte_1.SelectTextAll()
    
    ls_selected = windowName.rte_1.SelectedText()
    
    windowName.rte_1.SelectedTextLength = 0
    
    //assign the string content to the ActiveX control
    
    windowName.ole_1.object.text = ls_selected
    
    windowName.ole_1.object.start()
    
  6. Select the ActiveX control in the Window painter and select ReplaceWord from the event list for the control.

  7. Add the following code to the ReplaceWord event script:

    string str
    
    str = this.object.MisspelledWord
    
    rte_1.SelectedStartPos = this.object.WordOffset 
    
    rte_1.SelectedTextLength  = Len(str) 
    
    rte_1.ReplaceText(this.object.ReplacementWord)
    
    messagebox("misspelled word", "replaced")
    

    The next time you run the application, you can click the Check Spelling menu item to spell check the entire contents of the current band of the RichTextEdit control.