How to use special characters in password type fields in the Visual LANSA component of LANSA for Windows
|Product/Release:||LANSA for Windows|
|Abstract:||Putting password type characters on fields in the Visual LANSA component of LANSA for Windows|
|Submitted By:||LANSA Technical Support|
When designing applications using the Visual LANSA component of LANSA for Windows programmers assume that putting input and output attributes on fields works the same was as it does for writing LANSA for Windows functions. There are, however, some subtle differences. For example, one field attribute that developers might commonly wish to use is the ND (non display hidden field) on password type fields. However, they find that putting the ND attribute on a field used on a form seems to be ignored at execution time and when they type into the field the characters display despite the ND attribute being specified.
However, there is a different methodology used when specifying a password type field in the Visual LANSA component of LANSA for Windows. To specify a password type field on a form you should do the following:
- Open a new or existing form in the component editor.
- From the Repository tabsheet select Boxes and expand it by clicking on the + next to it.
- When the Boxes is expanded a list of the different types of boxes available. Select PRIM_EDIT (Edit Box) and drag it onto the form.
- Now click on the Component tabsheet and the Properties and Events for this Edit Box (EDIT_1) should be displayed.
- Scan down the list of properties for this edit box to a Property called PasswordChar. Click the mouse in the entry box for this property and it will become editable.
- Now specify any character, generally an asterisk (*), as the password character. This is the character which will be shown when the password is typed in at execution time. For more information select Help -> Features with the focus still on the PasswordChar property and the help will go straight to this feature.
- Build and compile the component. Select Ctrl+E to execute it and by typing in the edit box it will display the selected character as the PasswordChar property.
- A simple example of how this works is provided below. This example can be copied directly into the component source editor.
To copy this example directly into the Component source editor, do the following:
- Create a new form in the Work with Fields. Click OK and the Component Editor is opened.
- Go to the Source Editor either by clicking on the Source tab or by pressing F9.
- Use Ctrl+A to Select All. Then press the Delete button. The source editor should now be empty of all code.
- Copy all the code below into the Component Editor and Save.
- Build, compile and execute.
* **************************************************; * ; * COMPONENT: STD_FORM ; * ; * **************************************************; FUNCTION OPTIONS(*DIRECT); BEGIN_COM BORDERICONS(Maximize+Minimize+SystemMenu) CAPTION('Password Test') FORMPOSITION(ScreenCenter) HEIGHT(203) WIDTH(380); DEFINE_COM CLASS(#PRIM_EDIT) NAME(#EDIT_1) DISPLAYPOSITION(1) HEIGHT(19) LEFT(108) PARENT(#COM_OWNER) PASSWORDCHAR(*) SHOWSELECTION(False) TABPOSITION(1) TOP(48) WIDTH(60); DEFINE_COM CLASS(#USER.Visual) NAME(#USER) CAPTION('Current User :') DISPLAYPOSITION(2) HEIGHT(19) LABELTYPE(Caption) LEFT(8) MARGINLEFT(100) PARENT(#COM_OWNER) READONLY(True) TABPOSITION(2) TOP(15) WIDTH(160); DEFINE_COM CLASS(#PRIM_LABL) NAME(#LABL_1) CAPTION('Password :') DISPLAYPOSITION(3) HEIGHT(19) LEFT(8) PARENT(#COM_OWNER) TABPOSITION(3) TABSTOP(False) TOP(48) WIDTH(81); DEFINE_COM CLASS(#PRIM_STBR) NAME(#STBR_1) DISPLAYPOSITION(4) HEIGHT(24) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(4) TABSTOP(False) TOP(152) WIDTH(372); DEFINE_COM CLASS(#PRIM_PHBN) NAME(#CHECKBTN) CAPTION('Check Password ') DISPLAYPOSITION(5) LEFT(32) PARENT(#COM_OWNER) TABPOSITION(5) TOP(112) WIDTH(135); DEFINE_COM CLASS(#PRIM_PHBN) NAME(#HINTBTN) CAPTION('Hint ') DISPLAYPOSITION(6) HINT('The password is xyz') LEFT(224) PARENT(#COM_OWNER) TABPOSITION(6) TOP(112); * ; define #use_passw *char 10 default(*blanks); * ; EVTROUTINE handling(#com_owner.Initialize); SET #com_owner caption(*component_desc); CHANGE FIELD(#USER) TO(USER); ENDROUTINE ; * ; EVTROUTINE HANDLING(#CHECKBTN.Click); CHANGE #USE_PASSW #EDIT_1.VALUE; IF COND('#USE_PASSW *EQ ''xyz'''); MESSAGE MSGTXT('Correct password. Well done!') ; else; MESSAGE MSGTXT('Wrong password. Try clicking on the Hint button.') ; ENDIF; ENDROUTINE; * ; EVTROUTINE HANDLING(#HINTBTN.Click); MESSAGE MSGTXT('The password is xyx'); ENDROUTINE; * ; EVTROUTINE HANDLING(#EDIT_1.GotFocus); ENDROUTINE; END_COM ;