Page History
この例では、ドラッグ・アンド・ドロップ操作で複数の社員の詳細を操作し、その詳細を1つのEmployeeオブジェクトに保存することを除くとリスト・コレクションの例1と同じです。
[ |../../index.htm#lansa/l4wdev06_1075.htm]
現在地:
...
この例では、ドラッグ・アンド・ドロップ操作で複数の社員の詳細を操作し、その詳細を1つのEmployeeオブジェクトに保存することを除くとリスト・コレクションの例1と同じです。
Employeeオブジェクト
Employeeオブジェクトは、社員の詳細を保存するために使用されます。このオブジェクトは、その後、コレクション内でドラッグ・アンド・ドロップ操作で使用されます。
オブジェクトは、以下の社員のプロパティを定義し、公開しています。
- Empno
- GiveName
- SurName
- Deptment
- Salary
- PostCode
コレクションの定義
List コレクションは、このドラッグ操作でPayLoadとして動的に作成されます。#EmployeeオブジェクトのList コレクションです。コレクションに挿入されるEmployeeオブジェクトを保存するために#DragEmployee変数が作成されます。コレクションは動的なので、明示的にSET_REFコマンドで参照を設定する必要があります。
Define_Com Class(#Prim_LCOL<#Employee>) Name(#PayLoadList) Reference(*Dynamic)Define_Com Class(#Employee) Name(#DragEmployee) Reference(*Dynamic)Set_
...
Ref Com(#PayLoadList)
...
To(*Create_
...
as #Prim_LCOL<#Employee>)
...
コレクションへのアイテムの追加
コレクションへのアイテムの追加
選択されたEmployeeオブジェクトをList コレクションに追加するために、Selectlistループが使用されます。List コレクションは、ドラッグ操作のPayLoadとして割り当てられます。
Selectlist Named(#DRAG_LIST)Continue If('#Drag_List.Currentitem.Selected *ne True') Set_Ref Com(#DragEmployee) To(*Create_as #Employee) Set Com(#DragEmployee) Pempno(#Empno) Pgivename(#GiveName) Psurname(#Surname) Psalary(#Salary) Pdepartment(#Deptment) Ppostcode(#PostCode) Invoke Method(#PayLoadList.Insert) Item(#DragEmployee) Endselect Set_
...
Ref Com(#PayLoad)
...
To(#PayLoadList)
...
コレクションからのアイテムの取得
2つめのフォームのリストのDragDropイベントには、List コレクションが定義され、選択された社員のコレクションを含むPayLoadがキャストされます。
Define_
...
Com Class(#Prim_LCOL<#Employee>)
...
Name(#EmployeePayLoad)
...
Reference(*Dynamic)Set_
...
Ref Com(#EmployeePayLoad)
...
To(*
...
Dynamic #PayLoad)
...
List コレクションの先頭から末尾まで、For/EndForループで社員の詳細を取得します。
For Each(#EmployeeObject) In(#EmployeePayLoad)Change Field(#EMPNO) To('#EMPLOYEEOBJECT.PEMPNO')Change Field(#GIVENAME) To('#EMPLOYEEOBJECT.PGIVENAME')Change Field(#SURNAME) To('#EMPLOYEEOBJECT.PSURNAME')Change Field(#POSTCODE) To('#EMPLOYEEOBJECT.PPOSTCODE')Add_Entry To_List(#DROP_LIST)Endfor
...
List コレクションの例2のソース・コード
Employeeオブジェクト
オブジェクトを再利用可能パーツとして作成します。この例では、#Employeeという名前にします。
Function Options(*DIRECT)Begin_
...
Com Role(*
...
EXTENDS #PRIM_OBJT)
...
* ----------------------------* This is an "Employee" object*
...
----------------------------
...
* Define the member variables that define an "Employee"
...
object ....
...
Define_Com Class(#Empno)Define_Com Class(#GiveName)Define_Com Class(#SurName)Define_Com Class(#Deptment)Define_Com Class(#Salary)Define_
...
Com Class(#PostCode)
...
* Publish the properties that an "Employee"
...
exposes .....
...
Define_Pty Name(pEmpno) Get(*Auto #Empno) Set(*Auto #Empno)Define_Pty Name(pGiveName) Get(*Auto #GiveName) Set(*Auto #GiveName)Define_Pty Name(pSurName) Get(*Auto #SurName) Set(*Auto #SurName)Define_Pty Name(pDepartment) Get(*Auto #Deptment) Set(*Auto #Deptment)Define_Pty Name(pSalary) Get(*Auto #Salary) Set(*Auto #Salary)Define_
...
Pty Name(pPostCode)
...
Get(*
...
Auto #PostCode)
...
Set(*
...
Auto #PostCode)
...
End_Com
...
初めのフォーム
...
Function Options(*DIRECT)Begin_
...
Com Role(*
...
EXTENDS #PRIM_FORM)
...
Clientheight(319)
...
Clientwidth(509)
...
Dragstyle(Automatic)
...
Height(346)
...
Left(255)
...
Top(111)
...
Width(517)
...
* The Drag List Definition.Note the use of the DragStyle(Automatic)
...
propertyDefine_
...
Com Class(#PRIM_LTVW)
...
Name(#DRAG_LIST)
...
Displayposition(1)
...
Dragstyle(Automatic)
...
Fullrowselect(True)
...
Height(285)
...
Left(8)
...
Parent(#COM_OWNER)
...
Tabposition(1)
...
Top(8)
...
Width(465)Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_1)
...
Displayposition(1)
...
Parent(#DRAG_LIST)
...
Source(#EMPNO)
...
Width(18)Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_2)
...
Displayposition(2)
...
Parent(#DRAG_LIST)
...
Source(#SALARY)
...
Width(20)Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_3)
...
Displayposition(3)
...
Parent(#DRAG_LIST)
...
Source(#SURNAME)
...
Width(20)Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_4)
...
Displayposition(4)
...
Parent(#DRAG_LIST)
...
Source(#GIVENAME)
...
Width(20)Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_5)
...
Displayposition(5)
...
Parent(#DRAG_LIST)
...
Source(#DEPTMENT)
...
Width(11)Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_6)
...
Displayposition(6)
...
Parent(#DRAG_LIST)
...
Source(#POSTCODE)
...
Width(20)
...
Widthtype(Remainder)
...
* Define the drop form (change #LCOL00004 to the name you give to the second form)Define_Com Class(#LCOL00004)
...
*
...
===============================*
...
Handle main form initialization*
...
===============================
...
Evtroutine Handling(#com_owner.Initialize)
...
* Fill the drag list with employee detailsSelect Fields(#DRAG_LIST)
...
From_File(PSLMST)Add_
...
Entry To_List(#DRAG_LIST)Endselect
...
* Show the drop list form (change #LCOL00004 to the name you give to the second form)Invoke Method(#LCOL00004.ShowForm)
...
Endroutine
...
*
...
==================================
...
* Handle starting the drag operation* ==================================
...
Evtroutine Handling(#Drag_List.StartDrag)
...
Draglist(#DragList)
...
Continue(#Continue)
...
Payload(#PayLoad)Define_
...
Com Class(#Prim_LCOL<#Employee>)
...
Name(#PayLoadList)
...
Reference(*Dynamic)Define_
...
Com Class(#Employee)
...
Name(#DragEmployee)
...
Reference(*Dynamic)
...
* Dynamically create the list collection that is to to be the "payload"*
...
for this drag operation.It is a list collection of #Employee objectsSet_Ref Com(#PayLoadList)
...
To(*Create_
...
as #Prim_LCOL<#Employee>)
...
* Now fill the list collection with the employees that are selectedSelectlist Named(#DRAG_LIST)
...
Continue If('#Drag_List.Currentitem.
...
Selected *
...
ne True')Set_
...
Ref Com(#DragEmployee)
...
To(*Create_
...
as #Employee)Set Com(#DragEmployee)
...
Pempno(#Empno)
...
Pgivename(#GiveName)
...
Psurname(#Surname)
...
Psalary(#Salary)
...
Pdepartment(#Deptment)
...
Ppostcode(#PostCode)
...
Invoke Method(#PayLoadList.Insert)
...
Item(#DragEmployee)Endselect
...
*
...
Finished.Set the correct return valuesSet Com(#Continue)
...
Value(True)Set_
...
Ref Com(#PayLoad)
...
To(#PayLoadList)
...
Set Com(#DragList)
...
Dragliststyle(Selection)
...
Endroutine
...
End_Com
...
2番目のフォーム
...
Function Options(*DIRECT)Begin_
...
Com Role(*
...
EXTENDS #PRIM_FORM)
...
Clientheight(433)
...
Clientwidth(331)
...
Dragstyle(Automatic)
...
Formstyle(StayOnTopChild)
...
Height(460)
...
Left(453)
...
Top(49)
...
Width(339)
...
* The Drop List DefinitionDefine_
...
Com Class(#PRIM_LTVW)
...
Name(#DROP_LIST)
...
Displayposition(1)
...
Dragstyle(Automatic)
...
Fullrowselect(True)
...
Height(418)
...
Left(6)
...
Parent(#COM_OWNER)
...
Tabposition(1)
...
Top(7)
...
Width(321)Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_1)
...
Displayposition(1)
...
Parent(#DROP_LIST)
...
Source(#EMPNO)
...
Width(18)Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_3)
...
Displayposition(2)
...
Parent(#DROP_LIST)
...
Source(#SURNAME)
...
Width(20)Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_4)
...
Displayposition(3)
...
Parent(#DROP_LIST)
...
Source(#GIVENAME)
...
Width(40)Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_6)
...
Displayposition(4)
...
Parent(#DROP_LIST)
...
Source(#POSTCODE)
...
Width(20)
...
Widthtype(Remainder)
...
*
...
===============================
...
* Handle Drag Over the drop list* ===============================
...
Evtroutine Handling(#Drop_List.DragOver)
...
Acceptdrop(#AcceptDrop)
...
Payload(#PayLoad)
...
* If the payload to be dropped is a list collection of employees* then accept it otherwise reject it .....
...
If_
...
Ref Com(#PayLoad)
...
Is(*Instance_
...
of #Prim_LCol<#Employee>)
...
Set Com(#AcceptDrop)
...
Value(True)Else
...
Set Com(#AcceptDrop)
...
Value(False)Endif
...
Endroutine
...
*
...
=========================================
...
* Handle the actual drop into the drop list* =========================================
...
Evtroutine Handling(#Drop_List.DragDrop)
...
Payload(#PayLoad)Define_
...
Com Class(#Prim_LCOL<#Employee>)
...
Name(#EmployeePayLoad)
...
Reference(*Dynamic)
...
* Cast the payload as a list collection of employee objects ....
...
Set_
...
Ref Com(#EmployeePayLoad)
...
To(*
...
Dynamic #PayLoad)
...
* Fill drop list with all the employee numbers in the payload ...
...
Clr_
...
List Named(#DROP_LIST)
...
For Each(#EmployeeObject)
...
In(#EmployeePayLoad)
...
Change Field(#EMPNO)
...
To('#EMPLOYEEOBJECT.PEMPNO')
...
Change Field(#GIVENAME)
...
To('#EMPLOYEEOBJECT.PGIVENAME')
...
Change Field(#SURNAME)
...
To('#EMPLOYEEOBJECT.PSURNAME')
...
Change Field(#POSTCODE)
...
To('#EMPLOYEEOBJECT.PPOSTCODE')Add_
...
Entry To_List(#DROP_LIST)Endfor
...
Endroutine
...
End_Com
...
