次のソースを使用して、FLDVIS01という名前の再利用可能パーツを作成します。これにより、フィールドDEPTMENTにオートコンプリート機能が実現します。
Function Options(*DIRECT)Begin_Com Role(*EXTENDS #PRIM_PANL *implements #Prim_dc.iMonitorSubject) Defaultpty(Value) Displayposition(1) Height(20) Layoutmanager(#ATLM_1) Left(0) Tabposition(1) Top(0) Width(150)Define_Com Class(#PRIM_ATLM) Name(#ATLM_1)Define_Com Class(#DEPTMENT.VisualEdit) Name(#Department) Displayposition(1) Height(20) Marginleft(0) Parent(#COM_OWNER) Tabposition(1) Width(150)Define_Com Class(#PRIM_ATLI) Name(#ATLI_1) Attachment(Center) Manage(#Department) Parent(#ATLM_1)Define_Pty Name(Value) Get(GetPropertyValue) Set(SetPropertyValue)Ptyroutine Name(GetPropertyValue)Define_Map For(*Output) Class(#prim_alph) Name(#Property)#Property := #DepartmentEndroutinePtyroutine Name(SetPropertyValue)Define_Map For(*Input) Class(#prim_alph) Name(#Property)#Department := #PropertyEndroutineMthroutine Name(ApplymonitoredValue) Options(*redefine)* No redefinition requiredEndroutineMthroutine Name(GetValue) Options(*redefine)* No redefinition requiredEndroutineEvtroutine Handling(#Department.KeyPress) Handled(#Handled) Keycode(#KeyCode) Char(#Char)* If the field isn't fullIf (#Department.CurSize <> #Department.FieldLength)* If a character enteredIf (#KeyCode = isChar)#Com_Owner.PrepareAutoCompleteIf (#Com_owner.CanAutoComplete)#Handled := True#Com_owner.AutoComplete( #Char )Signal Event(ValueChanged)EndifEndifEndifEndroutineEvtroutine Handling(#Department.Changed)* Handle all other key presses that might affect the valueSignal Event(ValueChanged)EndroutineMthroutine 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 := (#Department.SelectionEnd = (#Department.Trim.cursize + 1))EndroutineMthroutine 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 := #Department.SelectionStart#Candidate := #Com_owner.PrepareCandidate( #Char )#Department := #Com_owner.GetCandidate( #Candidate )* Set selection to be startposition + 1 to the end#Department.SelectionStart := #Start + 1#Department.SelectionEnd := #Department.Trim.cursize + 1EndroutineMthroutine 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 pointsIf (#Department.SelectionStart > #Department.SelectionEnd)#Transition := #Department.SelectionStart#Department.SelectionStart := #Department.SelectionEnd#Department.SelectionEnd := #TransitionEndifEndroutineMthroutine 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 eventIf (#Department.SelectionStart = 1)#Result := #Char.uppercaseElse* Get anything to the left of the cursor start position and append the last key press#Result := (#Department.substring( 1 (#Department.SelectionStart - 1) ).trim + #Char).UppercaseEndifEndroutineMthroutine 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 valueSelect Fields(#Deptment) From_File(Deptab) With_Key(#Candidate) Generic(*yes)#Result := #DeptmentLeaveEndselectEndroutineEnd_Com
再利用可能なパーツが、DEPTMENTに対して単一の入力ボックスしか表示していないことに注意してください。ラベルや説明は必要ありません。
フィールドDEPTMENTを開き、[ビジュアライゼーション]タブに移動します。
[新しいビジュアルホスト]のオプションを選択し、プロンプトでFLDVIS01を選択します。DEPTMENTは、以下のようになります。
これで、新しいVisual_host再利用可能パーツを次のように使用できます。
Define_Com Class(#Deptment.Visualhost) Name(#...)
VisualHostの省略時の名前をAutoCompleteのような名前にしてもかまいません。そうすると、フォームで使用した場合に次のように表示されます。
Define_Com Class(#Deptment.AutoComplete) Name(#...)

