部署の動的ピックリストを作成しましたが、課、さらには社員のピックリストが必要になっても不思議ではありません。
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.RemoveAllSelect Fields(*all) From_File(Sectab) With_Key(#Deptment)#Picklist.Add( #Section #Secdesc )EndselectEndroutineMthroutine Name(ApplyMonitoredValue) Options(*Redefine)#Deptment := #MonitorSubject.GetValueEndroutineEnd_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 := *nullSelect Fields(#Section) From_File(sectab) With_Key(#Deptment)LeaveEndselectEndroutineEnd_Com
フォームの変数値は依然として維持しなければならないことに注意してください。ユーザーは必ず、Deptmentが変更されたときに、Sectionが合理的な値に変更されるようにしなければなりません。ここでは、部署の新しい値に対する、テーブルの最初の部分です。
次のコードは、EMPNO の動的ピックリストです。
Function Options(*DIRECT)Begin_Com Role(*EXTENDS #PRIM_OBJT *implements #Prim_dc.iDynamicPicklist #Prim_dc.iMonitorSubject)Mthroutine Name(Load) Options(*redefine)#Picklist.RemoveAllSelect Fields(*all) From_File(pslmst1) With_Key(#Deptment #Section)#Picklist.Add( #Empno ("&1 &2 (&3)").Substitute( #Givename #Surname #Empno ) )EndselectEndroutineMthroutine Name(ApplyMonitoredValue) Options(*Redefine)Case ((#MonitorSubject *As #Prim_objt).ComponentPatternName)When (= Deptment)#Deptment := #MonitorSubject.GetValueWhen (= Section)#Section := #MonitorSubject.GetValueEndcaseEndroutineEnd_Com
考え方としては、課のコードとおおむね同じです。ただし、ApplyMonitorValue への変更に注意してください。Empno は、Deptment と Section の両方の値を知る必要があります。受け取られた iMonitorSubject はソース・コンポーネントの参照であるため、ComponentPatternName を使用して、変更があった変数を判断できます。
ComponentPatternName はフィールド識別子を返すため、10 文字以上のフィールドに対してこのコードを利用する場合や、Identifer が Field Name と異なる場合は注意してください。
その後、Empno を次のようにフォームに追加した場合、さらに2つのモニターを追加して、Deptment と Sectionへの変更を 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.GetDefaultEmpnoEndroutineEvtroutine Handling(#Section.Changed)* Ensure the Empno is valid after a department change#Com_owner.GetDefaultEmpnoEndroutineMthroutine Name(GetDefaultSection) Access(*private)#Section := *nullSelect Fields(#Section) From_File(sectab) With_Key(#Deptment)LeaveEndselectEndroutineMthroutine Name(GetDefaultEmpno) Access(*private)#Empno := *nullSelect Fields(#Empno) From_File(pslmst1) With_Key(#Deptment #Section)LeaveEndselectEndroutineEnd_Com