|
Use WPSpell |
Top Previous Next |
|
WPSpell is an addon to WPTools.
1) Please add the required units to the uses clause
uses WPSpell_link, WPSpell_Controller, WPSpell_OptForm, WPSpell_StdForm
2) Create a TWPSpellController (you can also drop the component on the form) and set the properties. (Note: This step is not required if you are using the DEMO version since here the SpellController is provided by a DLL - the registered version does not use a DLL)
in TForm we need a variable: FSpellControler : TWPSpellController;
This variable is initialized in the event OnCreate
procedure TForm1.FormCreate(Sender: TObject); begin FSpellControler := TWPSpellController.Create(self); FSpellControler.PersistencyMode := wpUseRegistry; FSpellControler.Active := TRUE; FSpellControler.LoadSetup(false); // UpdateLanguges; - this procedure fills a combobx end;
procedure TForm1.FormDestroy(Sender: TObject); begin FSpellControler.AutoSaveSetup; FSpellControler.Free; end;
3) Switch SpellAsYouGo on and off (Spell is a checkbox in this example)
procedure TForm1.SpellClick(Sender: TObject); begin if Spell.Checked then WPRichText1.StartSpellCheck(wpStartSpellAsYouGo) else WPRichText1.StartSpellCheck(wpStopSpellAsYouGo); end;
4) Add a configure button or menu item
procedure TForm1.ConfigureClick(Sender: TObject); begin if FSpellControler.Configure then begin // UpdateLanguges; - if we update a combobox if Spell.Checked then begin WPRichText1.StartSpellCheck(wpStopSpellAsYouGo); WPRichText1.StartSpellCheck(wpStartSpellAsYouGo); end; end; end;
alternatively you can also call: WPRichText1.StartSpellCheck(wpShowSpellCheckSetup);
5) If you want to show a combobox with the available dictionaries
// This procedure updates the combobox procedure TForm1.UpdateLanguges; var i, j : Integer; begin // Checkbox Spell.Checked := (FSpellControler.OptionFlags and WPSPELLOPT_SPELLASYOUGO)<>0; // ComboBox SpellLanguages.Items.Clear; j := -1; for i:=0 to FSpellControler.LanguageIDCount-1 do begin if FSpellControler.CurrentLanguage=FSpellControler.LanguageID[i] then j := SpellLanguages.Items.Count; SpellLanguages.Items.AddObject(FSpellControler.LanguageName[i], Pointer(FSpellControler.LanguageID[i])); end; SpellLanguages.ItemIndex := j; end;
//this procedure applies a language change procedure TForm1.SpellLanguagesChange(Sender: TObject); begin if SpellLanguages.ItemIndex>=0 then begin FSpellControler.CurrentLanguage := Integer(SpellLanguages.Items.Objects[SpellLanguages.ItemIndex]); if Spell.Checked then begin WPRichText1.StartSpellCheck(wpStopSpellAsYouGo); WPRichText1.StartSpellCheck(wpStartSpellAsYouGo); end; end; end;
The property CurrentLanguage is used to select the current dictionary. You have to use one of the language or language-group IDs which are defined in file WPLanguages.INC Example: English General = 9, English UD= 1033, English British = 2057, French = 1036, German = 1031, Italian= 1040, Spanish = 1034
|