現在地: Visual LANSA 開発者ガイド > 1. アプリケーション、フィールド、データベース、リポジトリの概要 > 1.5 フィールドの作成 > 例3 - 複数のビジュアライゼーションのリンク
例3 - 複数のビジュアライゼーションのリンク

部署の動的ピックリストを作成しましたが、課、さらには社員のピックリストが必要になっても不思議ではありません。

Sectionには次のコードを使用できます。前の例と同様に、Loadメソッドによりピックリストが取り込まれます。しかし、Sectionは実行時にDeptmentにリンクする必要があるため、再利用可能パーツにはiMonitorSubjectも実装します。

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_OBJT *implements #Prim_dc.iDynamicPicklist #Prim_dc.iMonitorSubject)
 
Mthroutine Name(Load) Options(*redefine)
 
#Picklist.RemoveAll
 
Select Fields(*all) From_File(Sectab) With_Key(#Deptment)
 
#Picklist.Add( #Section #Secdesc )
 
Endselect
 
Endroutine
 
Mthroutine Name(ApplyMonitoredValue) Options(*Redefine)
 
#Deptment := #MonitorSubject.GetValue
 
Endroutine
 
End_Com
 

次のフォームでは、DeptmentとSectionの両方のビジュアライゼーションを使用しています。モニターが、Deptmentをソース、Sectionをターゲットとして定義されています。Deptmentが変更されると、SectionビジュアライゼーションのApplyMonitorValueメソッドが実行されます。ソース・オブジェクトへの参照が受け取られ、GetValueメソッドを呼び出して値を取得できるようになります。

ApplyMonitorValueが終了するとすぐに、Loadメソッドが実行されます。

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(304) Clientwidth(589) Left(277) Top(135) Width(605)
 
Define_Com Class(#Deptment.VisualPicklist) Name(#Deptment) Displayposition(1) Left(8) Parent(#COM_OWNER) Tabposition(1) Top(8) Width(401)
Define_Com Class(#Section.VisualPicklist) Name(#Section) Displayposition(2) Left(8) Parent(#COM_OWNER) Tabposition(2) Top(32) Width(401)
 
Define_Com Class(#prim_lm) Name(#DepartmentSection) Source(#Deptment) Target(#Section)
 
Evtroutine Handling(#Deptment.Changed)
 
* Ensure the Section is valid after a department change
#Section := *null
 
Select Fields(#Section) From_File(sectab) With_Key(#Deptment)
Leave
Endselect
 
Endroutine
End_Com
 

フォームの変数値は依然として維持しなければならないことに注意してください。ユーザーは必ず、Deptmentが変更されたときに、Sectionが合理的な値に変更されるようにしなければなりません。ここでは、部署の新しい値に対する、テーブルの最初の部分です。

The code following is for a dynamic picklist for EMPNO.

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_OBJT *implements #Prim_dc.iDynamicPicklist #Prim_dc.iMonitorSubject)
 
Mthroutine Name(Load) Options(*redefine)
 
#Picklist.RemoveAll
 
Select Fields(*all) From_File(pslmst1) With_Key(#Deptment #Section)
 
#Picklist.Add( #Empno ("&1 &2 (&3)").Substitute( #Givename #Surname #Empno ) )
 
Endselect
 
Endroutine
 
Mthroutine Name(ApplyMonitoredValue) Options(*Redefine)
 
Case ((#MonitorSubject *As #Prim_objt).ComponentPatternName)
 
When (= Deptment)
#Deptment := #MonitorSubject.GetValue
 
When (= Section)
#Section := #MonitorSubject.GetValue
 
Endcase
 
Endroutine
 
End_Com
 

考え方としては、課のコードとおおむね同じです。ただし、ApplyMonitorValue への変更に注意してください。Empno は、DeptmentSection の両方の値を知る必要があります。受け取られた iMonitorSubject はソース・コンポーネントの参照であるため、ComponentPatternName を使用して、変更があった変数を判断できます。

ComponentPatternName はフィールド識別子を返すため、10 文字以上のフィールドに対してこのコードを利用する場合や、IdentiferField Name と異なる場合は注意してください。

その後、Empno を次のようにフォームに追加した場合、さらに2つのモニターを追加して、DeptmentSectionへの変更を Empno に通知する必要があります。

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(304) Clientwidth(589) Left(277) Top(135) Width(605)
 
Define_Com Class(#Deptment.VisualPicklist) Name(#Deptment) Displayposition(1) Left(8) Parent(#COM_OWNER) Tabposition(1) Top(8) Width(401)
Define_Com Class(#Section.VisualPicklist) Name(#Section) Displayposition(2) Left(8) Parent(#COM_OWNER) Tabposition(2) Top(32) Width(401)
Define_Com Class(#EMPNO.VisualPicklist) Name(#Empno) Displayposition(3) Left(8) Parent(#COM_OWNER) Tabposition(3) Top(56) Width(401)
 
Define_Com Class(#prim_lm) Name(#DepartmentSection) Source(#Deptment) Target(#Section)
Define_Com Class(#prim_lm) Name(#SectionEmployee) Source(#Section) Target(#Empno)
Define_Com Class(#prim_lm) Name(#DepartmentEmployee) Source(#Deptment) Target(#Empno)
 
Evtroutine Handling(#Deptment.Changed)
* Ensure the Section and Empno are valid after a department change
#Com_owner.GetDefaultSection
#Com_owner.GetDefaultEmpno
Endroutine
 
Evtroutine Handling(#Section.Changed)
* Ensure the Empno is valid after a department change
#Com_owner.GetDefaultEmpno
Endroutine
 
Mthroutine Name(GetDefaultSection) Access(*private)
 
#Section := *null
 
Select Fields(#Section) From_File(sectab) With_Key(#Deptment)
Leave
Endselect
 
Endroutine
 
Mthroutine Name(GetDefaultEmpno) Access(*private)
 
#Empno := *null
 
Select Fields(#Empno) From_File(pslmst1) With_Key(#Deptment #Section)
Leave
Endselect
 
Endroutine
 
End_Com