Tech Tip: Alternative to using the Auto-spellcheck form object property
PRODUCT: 4D | VERSION: 12.1 | PLATFORM: Mac & Win
Published On: March 17, 2011
Having a form object property like Auto Spellcheck is very nice—set it and forget it! But, it would also be convenient to have an alternative to setting this property for every alpha or text field or variable on a form. Especially so if the form has many of them. Well, there is an alternative and it is the 4D command SPELL CHECKING.
The alternative is to incorporate SPELL CHECKING into a form so it is only done once and it is active for all alpha and text fields and variables. The technique of how to do it is explained below:
First, enter the Project method SpellChecker, shown below, into the database application.
If (True) If (False) //***************************************************************************** // // SpellChecker($TxtVar_P) // // Purpose: Spellcheck an alpha or text var // // $1 - Pointer - To the variable about to loose focus // //***************************************************************************** End if C_TEXT($MethodName_T) $MethodName_T:=Current method name //===================== Declare Variables ================================== //method_parameters_declarations C_POINTER($TxtVar_P;$1) //---------------------------------------------------------------------------- //method_wide_constants_declarations //---------------------------------------------------------------------------- //local_variable_declarations C_LONGINT($Params_L) End if //====================== Initialize and Setup ================================ $TxtVar_P:=$1 If ((Type($TxtVar_P->)=Is Alpha Field)\ | (Type($TxtVar_P->)=Is String Var)\ | (Type($TxtVar_P->)=Is Text)) //======================== Method Actions ================================== SPELL CHECKING //======================== Clean up and Exit ================================= $TxtVar_P->:=Get edited text End if |
Next, for the form, make sure that the proper Form Events are active, most likely the Form events of On Data Change or On Losing Focus, in this example the Form Event On Losing Focus is the trigger.
As shown in the Form method snippet below, call the Project method SpellChecker when the event fires. The 4D function Focus object is used to pass a pointer to the current form variable to the method.
The method SpellChecker calls the SPELL CHECKING command, that triggers the spell check of the field or variable that has focus in the currently displayed form. If all is spelled correctly the focus moves on to the next object. If unknown words are encountered the SPELL CHECKING dialog is presented to the user. The user makes the correction and the 4D function Get edited text replaces the errors with the edited text.
//-------------------------------------------------------------------------------- //local_variable_declarations C_LONGINT($FormEvt_L) C_POINTER($Text_P) //=========================== Initialize and Setup =========================== $FormEvt_L:=Form event //=========================== Method Actions =========================== Case of : ($FormEvt_L=On Close Box) CANCEL //------------------------------------------------------------------------------ : ($FormEvt_L=On Load) //insert_code_here // //------------------------------------------------------------------------------ : ($FormEvt_L=On Getting Focus) //insert_code_here // //------------------------------------------------------------------------------ : ($FormEvt_LEvt_L=On Losing Focus) SpellChecker (Focus object) // //------------------------------------------------------------------------------ : ($FormEvt_L=On Clicked) //insert_code_here // //------------------------------------------------------------------------------ : ($FormEvt_L=On Outside Call) //insert_code_here // //------------------------------------------------------------------------------ End case |