Visual Lansa’s field visualization capabilities are very powerful. I have come across many areas in code where the visual display of data is manipulated in code within forms and reusable parts…only to be duplicated in other forms and reusable parts. Inevitably, this leads to bugs as different areas of an application behave differently (never mind the terrible inefficiency). In Lansa you can create a reusable part to act as a visual class for a field or multiple fields. In the example below, the original form contained code to display a field “prompt” to indicate the data required without taking up space with a label. The amount of code just to manage the prompt text was extraneous and redundant. This was refactored into a single reusable part and added to each fields visualization as defined below. One could easily take this code a step further and add formatting and validation routines for common data types like currency, phone numbers, email addresses, etc. If you are writing Visual Lansa applications in RDMLX and are not using field visualizations I would highly recommend looking into their use!
Field Visualization Reusable Part Code:
FUNCTION OPTIONS(*DIRECT)
BEGIN_COM ROLE(*EXTENDS #PRIM_PANL) DEFAULTPTY(Value) DISPLAYPOSITION(1) HEIGHT(18) LAYOUTMANAGER(#ATLM_1) LEFT(0) TABPOSITION(1) TABSTOP(False) TOP(0) WIDTH(200)
* =======================================================
* Component Definitions
* =======================================================
DEFINE_COM CLASS(#PRIM_ALPH) NAME(#PasswordChar)
DEFINE_COM CLASS(#PRIM_BOLN) NAME(#RequiredField)
DEFINE_COM CLASS(#PRIM_EDIT) NAME(#EditBox) DISPLAYPOSITION(1) HEIGHT(18) LEFT(0) PARENT(#COM_OWNER) SHOWSELECTION(False) SHOWSELECTIONHILIGHT(False) TABPOSITION(1) TOP(0) WIDTH(200)
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_1) ATTACHMENT(Center) MANAGE(#EditBox) PARENT(#ATLM_1)
DEFINE_COM CLASS(#PRIM_ATLM) NAME(#ATLM_1)
* =======================================================
* Field Definitions
* =======================================================
DEFINE FIELD(#wNme) TYPE(*CHAR) LENGTH(10)
DEFINE FIELD(#wRet) TYPE(*CHAR) LENGTH(2)
DEFINE FIELD(#wTyp) TYPE(*CHAR) LENGTH(1)
DEFINE FIELD(#wLen) TYPE(*DEC) LENGTH(15) DECIMALS(0)
DEFINE FIELD(#wDec) TYPE(*DEC) LENGTH(15) DECIMALS(0)
DEFINE FIELD(#wChr) TYPE(*DEC) LENGTH(15) DECIMALS(0)
DEFINE FIELD(#wRef) TYPE(*CHAR) LENGTH(10)
DEFINE FIELD(#wDsc) TYPE(*CHAR) LENGTH(40)
DEFINE FIELD(#wLbl) TYPE(*CHAR) LENGTH(15)
DEFINE FIELD(#wHdg) TYPE(*CHAR) LENGTH(60)
DEFINE FIELD(#wOut) TYPE(*CHAR) LENGTH(40)
DEFINE FIELD(#wInp) TYPE(*CHAR) LENGTH(40)
* =======================================================
* Property Definitions
* =======================================================
DEFINE_PTY NAME(Value) GET(GetValue) SET(SetValue)
DEFINE_PTY NAME(ReadOnly) GET(GetReadOnly) SET(SetReadOnly)
DEFINE_PTY NAME(ShowError) GET(GetShowError) SET(SetShowError)
DEFINE_PTY NAME(PasswordChar) GET(*AUTO #PasswordChar) SET(*AUTO #PasswordChar)
DEFINE_PTY NAME(Required) GET(*AUTO #RequiredField) SET(*AUTO #RequiredField)
* =======================================================
* Event Definitions
* =======================================================
DEFINE_EVT NAME(Changed)
DEFINE_EVT NAME(GotFocus)
DEFINE_EVT NAME(LostFocus)
DEFINE_EVT NAME(KeyPress)
DEFINE_MAP FOR(*OUTPUT) CLASS(#STD_FLAG) NAME(#KeyCode)
DEFINE_MAP FOR(*OUTPUT) CLASS(#STD_FLAG) NAME(#Char)
DEFINE_MAP FOR(*OUTPUT) CLASS(#PRIM_BOLN) NAME(#IsAltDown)
DEFINE_MAP FOR(*OUTPUT) CLASS(#PRIM_BOLN) NAME(#IsControlDown)
DEFINE_MAP FOR(*OUTPUT) CLASS(#PRIM_BOLN) NAME(#IsShiftDown)
DEFINE_MAP FOR(*BOTH) CLASS(#PRIM_BOLN) NAME(#Handled)
* =======================================================
* Property Routines
* =======================================================
PTYROUTINE NAME(SetValue)
DEFINE_MAP FOR(*INPUT) CLASS(#PRIM_VAR) NAME(#Value)
#EditBox.Value := #Value
#COM_OWNER.SetFieldPrompt
ENDROUTINE
PTYROUTINE NAME(GetValue)
DEFINE_MAP FOR(*OUTPUT) CLASS(#PRIM_VAR) NAME(#Value)
IF (#EditBox.Value <> #wDsc)
#Value := #EditBox.Value
ENDIF
ENDROUTINE
PTYROUTINE NAME(SetReadOnly)
DEFINE_MAP FOR(*INPUT) CLASS(#PRIM_BOLN) NAME(#ReadOnly)
#EditBox.ReadOnly := #ReadOnly
#EditBox.AutoSelect := #ReadOnly.Not
#COM_OWNER.SetFieldPrompt
ENDROUTINE
PTYROUTINE NAME(GetReadOnly)
DEFINE_MAP FOR(*OUTPUT) CLASS(#PRIM_BOLN) NAME(#ReadOnly)
#ReadOnly := #EditBox.ReadOnly
ENDROUTINE
PTYROUTINE NAME(SetShowError)
DEFINE_MAP FOR(*INPUT) CLASS(#PRIM_BOLN) NAME(#ShowError)
#EditBox.ShowError := #ShowError
#COM_OWNER.SetFieldPrompt
ENDROUTINE
PTYROUTINE NAME(GetShowError)
DEFINE_MAP FOR(*OUTPUT) CLASS(#PRIM_BOLN) NAME(#ShowError)
#ShowError := #EditBox.ShowError
ENDROUTINE
* =======================================================
* Event Routines
* =======================================================
EVTROUTINE HANDLING(#COM_OWNER.CreateInstance) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
SET COM(#COM_OWNER) VISUALSTYLE(#VSSITAGRY)
#wNme := #COM_OWNER.ComponentPatternName
USE BUILTIN(GET_FIELD) WITH_ARGS(#wNme) TO_GET(#wRet #wTyp #wLen #wDec #wRef #wDsc #wLbl #wHdg #wOut #wInp)
IF (#COM_SELF.ComponentTag <> ”)
#wDsc := #COM_SELF.ComponentTag
ENDIF
ENDROUTINE
EVTROUTINE HANDLING(#EditBox.KeyPress) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS) KEYCODE(#KeyCode) CHAR(#Character) HANDLED(#Handled) ISALTDOWN(#AltDown) ISSHIFTDOWN(#ShiftDown) ISCONTROLDOWN(#ControlDown)
DEFINE_COM CLASS(#STD_FLAG) NAME(#KeyedCharacter)
IF ((*Not #Handled) *And (*Not #EditBox.ReadOnly))
IF (#KeyCode = IsChar)
#KeyedCharacter := #Character
IF (*Not #wInp.Uppercase.Contains( ‘LC’ ))
#KeyedCharacter := #KeyedCharacter.Uppercase
ENDIF
#Handled := True
IF (#EditBox.Value = #wDsc)
#wChr := #EditBox.SelectionEnd
#EditBox.Value := #KeyedCharacter
ELSE
IF (#EditBox.SelectionEnd <> #EditBox.SelectionStart)
IF (#EditBox.SelectionEnd > #EditBox.SelectionStart)
#wChr := #EditBox.SelectionStart
#EditBox.Value := #EditBox.Value.Replace( #EditBox.Value.Substring( #EditBox.SelectionStart (#EditBox.SelectionEnd – #EditBox.SelectionStart) ) #KeyedCharacter )
ELSE
#wChr := #EditBox.SelectionEnd
#EditBox.Value := #EditBox.Value.Replace( #EditBox.Value.Substring( #EditBox.SelectionEnd (#EditBox.SelectionStart – #EditBox.SelectionEnd) ) #KeyedCharacter )
ENDIF
ELSE
#wChr := #EditBox.SelectionEnd
#EditBox.Value := #EditBox.Value.InsertString( #KeyedCharacter #EditBox.SelectionEnd )
ENDIF
ENDIF
#EditBox.SelectionStart #EditBox.SelectionEnd := #wChr + 1
#COM_OWNER.SetFieldPrompt
SIGNAL EVENT(Changed)
ENDIF
ENDIF
SIGNAL EVENT(KeyPress) KEYCODE(#KeyCode) CHAR(#KeyedCharacter) ISALTDOWN(#AltDown) ISCONTROLDOWN(#ControlDown) ISSHIFTDOWN(#ShiftDown) HANDLED(#Handled)
ENDROUTINE
EVTROUTINE HANDLING(#EditBox.Changed) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
#COM_OWNER.SetFieldPrompt
SIGNAL EVENT(Changed)
ENDROUTINE
EVTROUTINE HANDLING(#EditBox.GotFocus) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
SIGNAL EVENT(GotFocus)
ENDROUTINE
EVTROUTINE HANDLING(#EditBox.LostFocus) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
SIGNAL EVENT(LostFocus)
ENDROUTINE
* =======================================================
* Method Routines
* =======================================================
MTHROUTINE NAME(SetFieldPrompt)
IF (#EditBox.Value.CurChars > 0)
IF (#EditBox.Value = #wDsc)
#EditBox.PasswordChar := ”
IF (#RequiredField)
#EditBox.VisualStyle <= #VSSITARED
ELSE
#EditBox.VisualStyle <= #VSSITAGRY
ENDIF
ELSE
#EditBox.PasswordChar := #PasswordChar
#EditBox.VisualStyle <= #VSSNRMBLK
ENDIF
ELSE
#EditBox.PasswordChar := ”
#EditBox.Value := #wDsc
#EditBox.VisualStyle <= #VSSITAGRY
ENDIF
ENDROUTINE
END_COM
Field Visualization Definition Code:
BEGIN_COM ROLE(*EXTENDS #PRIM_OBJT)
BEGIN_COM ROLE(*Visual #PRIM_EVEF) NAME(#VisualEdit) DEFAULTVISUAL(True) HEIGHT(18) MARGINLEFT(100) USEPICKLIST(False) WIDTH(200)
END_COM
BEGIN_COM ROLE(*Visual_Part #OBJFLDPRM) NAME(#VisualPrompt)
END_COM
END_COM
Normal Visual Style Code:
BEGIN_COM ROLE(*EXTENDS #PRIM_VS) DEFAULT(#SCHEME)
DEFINE_COM CLASS(#PRIM_VSS) NAME(#SCHEME) CAPTIONS(#CAPTION) TITLES(#CAPTION) VALUES(#VALUE)
DEFINE_COM CLASS(#PRIM_VSI) NAME(#CAPTION) FACENAME(‘Tahoma’) FONTSIZE(8) NORMBACKCOLOR(ButtonFace) TEXTCOLOR(Black)
DEFINE_COM CLASS(#PRIM_VSI) NAME(#VALUE) ALTERNBACKCOLOR(Window) BORDERSTYLE(3DLeft) FACENAME(‘Tahoma’) FONTSIZE(8) TEXTCOLOR(Black)
END_COM
Italic Gray Visual Style Code:
BEGIN_COM ROLE(*EXTENDS #PRIM_VS) DEFAULT(#SCHEME)
DEFINE_COM CLASS(#PRIM_VSS) NAME(#SCHEME) CAPTIONS(#CAPTION) TITLES(#CAPTION) VALUES(#VALUE)
DEFINE_COM CLASS(#PRIM_VSI) NAME(#CAPTION) FACENAME(‘Tahoma’) FONTSIZE(8) NORMBACKCOLOR(ButtonFace) TEXTCOLOR(Black)
DEFINE_COM CLASS(#PRIM_VSI) NAME(#VALUE) ALTERNBACKCOLOR(Window) BORDERSTYLE(3DLeft) FACENAME(‘Tahoma’) FONTSIZE(8) ITALIC(True) TEXTCOLOR(Gray)
END_COM
Italic Red Visual Style Code:
BEGIN_COM ROLE(*EXTENDS #PRIM_VS) DEFAULT(#SCHEME)
DEFINE_COM CLASS(#PRIM_VSS) NAME(#SCHEME) CAPTIONS(#CAPTION) TITLES(#CAPTION) VALUES(#VALUE)
DEFINE_COM CLASS(#PRIM_VSI) NAME(#CAPTION) FACENAME(‘Tahoma’) FONTSIZE(8) NORMBACKCOLOR(ButtonFace) TEXTCOLOR(Black)
DEFINE_COM CLASS(#PRIM_VSI) NAME(#VALUE) ALTERNBACKCOLOR(Window) BORDERSTYLE(3DLeft) FACENAME(‘Tahoma’) FONTSIZE(8) ITALIC(True) TEXTCOLOR(Red)
END_COM