VFW090 Appendix A

VLF Windows Application Development

VFW090 – Appendix A

VFW090 – Field Visualizations

Use the following code to create iiiVFW21 – Surname Autocomplete

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_PANL *implements #Prim_dc.iMonitorSubject) Defaultpty(Value) Displayposition(1) Height(21) Layoutmanager(#ATLM_1) Left(0) Tabposition(1) Top(0) Width(157)
Define_Com Class(#PRIM_ATLM) Name(#ATLM_1)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_1) Attachment(Center) Parent(#ATLM_1)
Define_Com Class(<FIELD>.VisualEdit) Name(<FIELD>) Displayposition(1) Height(21) Marginleft(0) Parent(#COM_OWNER) Tabposition(1) Width(157)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_2) Attachment(Center) Parent(#ATLM_1)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_3) Attachment(Center) Manage(<FIELD>) Parent(#ATLM_1)
Define_Pty Name(Value) Get(GetPropertyValue) Set(SetPropertyValue)
Ptyroutine Name(GetPropertyValue)
Define_Map For(*Output) Class(#prim_alph) Name(#Property)
#Property := <FIELD>
Endroutine
Ptyroutine Name(SetPropertyValue)
Define_Map For(*Input) Class(#prim_alph) Name(#Property)
<FIELD> := #Property
Endroutine
Mthroutine Name(ApplymonitoredValue) Options(*redefine)
* No redefinition required
Endroutine
Mthroutine Name(GetValue) Options(*redefine)
* No redefinition required
Endroutine
Evtroutine Handling(<FIELD>.KeyPress) Handled(#Handled) Keycode(#KeyCode) Char(#Char)
* If the field isn't full
If (<FIELD>.CurSize <> <FIELD>.FieldLength)
* If a character entered
If (#KeyCode = isChar)
#Com_Owner.PrepareAutoComplete
If (#Com_owner.CanAutoComplete)
#Handled := True
#Com_owner.AutoComplete( #Char )
Signal Event(ValueChanged)
Endif
Endif
Endif
Endroutine
Evtroutine Handling(<FIELD>.Changed)
* Handle all other key presses that might affect the value
Signal Event(ValueChanged)
Endroutine
Mthroutine Name(CanAutoComplete) Help('Can we autocomplete?') Access(*Private)
Define_Map For(*Result) Class(#prim_boln) Name(#Result)
* If selection doesn't start at the end of the value, autocomplete is not appropriate.
#Result := (<FIELD>.SelectionEnd = (<FIELD>.Trim.cursize + 1))
Endroutine
Mthroutine Name(AutoComplete) Access(*private)
Define_Map For(*Input) Class(#prim_alph) Name(#Char) Help('Character just pressed on the keyboard')
Define_Com Class(#prim_nmbr) Name(#Start)
Define_Com Class(#prim_alph) Name(#Candidate)
#Start := <FIELD>.SelectionStart
#Candidate := #Com_owner.PrepareCandidate( #Char )
<FIELD> := #Com_owner.GetCandidate( #Candidate )
* Set selection to be startposition + 1 to the end
<FIELD>.SelectionStart := #Start + 1
<FIELD>.SelectionEnd := <FIELD>.Trim.cursize + 1
Endroutine
Mthroutine Name(PrepareAutoComplete) Help('Prepare Selection in the value so that it runs left to right') Access(*private)
Define_Com Class(#prim_nmbr) Name(#Transition)
* If Start is greater than end, reverse the selection points
If (<FIELD>.SelectionStart > <FIELD>.SelectionEnd)
#Transition := <FIELD>.SelectionStart
<FIELD>.SelectionStart := <FIELD>.SelectionEnd
<FIELD>.SelectionEnd := #Transition
Endif
Endroutine
Mthroutine Name(PrepareCandidate) Help('Prepare the input value ready for looking up the next candidate') Access(*private)
Define_Map For(*Input) Class(#prim_alph) Name(#Char) Help('Character just pressed on the keyboard')
Define_Map For(*Result) Class(#Prim_alph) Name(#Result)
* If selection is the whole word, only use the char supplied by the event
If (<FIELD>.SelectionStart = 1)
#Result := #Char.uppercase
Else
* Get anything to the left of the cursor start position and append the last key press
#Result := (<FIELD>.substring( 1 (<FIELD>.SelectionStart - 1) ).trim + #Char).Uppercase
Endif
Endroutine
Mthroutine Name(GetCandidate) Access(*private)
Define_Map For(*Input) Class(#prim_alph) Name(#Candidate)
Define_Map For(*Result) Class(#prim_alph) Name(#Result)
* If no record found, the last value entered is still the right answer
#Result := #Candidate
* Find the first record starting with the candidate value
Select Fields(#SURNAME) From_File(pslmst2) With_Key(#Candidate) Generic(*yes)
#Result := #SURNAME
Leave
Endselect
Endroutine
End_Com