この例では、List コレクションを使用して、アイテムをフォームからフォームにドラッグ・アンド・ドロップする方法を説明します。
List コレクションは、順序付けされたコンポーネントのコレクションを提供します。List コレクションのコンポーネントは、指定された索引またはリストの先頭または末尾の参照で位置付けされます。インデックスには、常に1を基準とした値が付けられます。
この例では、ドラッグ・アンド・ドロップ操作の最初で選択された社員の社員番号と賃金情報がList コレクションに保存され、操作の最後にコレクションから他のフォームにこの情報が取得されます。
コレクションの定義
List コレクションは、社員のリストのStartDragイベントで動的に定義されます。この方法で、List コレクションの範囲がドラッグ操作に制限されます。選択された社員の社員番号を保存するために#Employee_Number変数が作成されます。コレクションは動的なので、明示的にSET_REFで作成される必要があります。
Define_Com Class(#Prim_LCOL<#Prim_ALPH>) Name(#PayLoadList) Reference(*Dynamic)Define_Com Class(#Prim_ALPH) Name(#EmployeeNumber) Reference(*Dynamic)Set_Ref Com(#PayLoadList) To(*Create_as #Prim_LCOL<#Prim_ALPH>)
コレクションへのアイテムの追加
選択された社員は、SELECTLISTループで追加されます。#Employee_Number変数は、選択された社員の社員番号を割り当てられ、INSERTメソッドでコレクションに追加されるアイテムの指定に使用されます。List コレクションは、PayLoadとして、またはドラッグ・アンド・ドロップ操作として割り当てられます。
Selectlist Named(#DRAG_LIST)Continue If('#Drag_List.Currentitem.Selected *ne True')Set_Ref Com(#EmployeeNumber) To(*Create_as #Prim_ALPH)Set Com(#EmployeeNumber) Value(#EmpNo)Invoke Method(#PayLoadList.Insert) Item(#EmployeeNumber)EndselectSet_Ref Com(#PayLoad) To(#PayLoadList)
コレクションからのアイテムの取得
選択された社員が他のフォームにドラッグされると、このフォームのリストのDragOverイベントでドロップされるPayLoadが英数字のList コレクションかどうかがテストされます。
Evtroutine Handling(#Drop_List.DragOver) Acceptdrop(#AcceptDrop) Payload(#PayLoad)If_Ref Com(#PayLoad) Is(*Instance_of #Prim_LCol<#Prim_alph>)Set Com(#AcceptDrop) Value(True)ElseSet Com(#AcceptDrop) Value(False)EndifEndroutine
他のList コレクションがリストのDragDropで定義され、PayLoadがコレクションにキャストされます。
Define_Com Class(#Prim_LCOL<#Prim_ALPH>) Name(#PayLoadList) Reference(*Dynamic)
* Cast the payload as a list colelction of alphas ....Set_Ref Com(#PayLoadList) To(*Dynamic #PayLoad)
社員は、FOR/ENDFORループでコレクションからリストに取得されます。
For Each(#EmployeeNumber) In(#PayLoadList)Change Field(#EMPNO) To('#EMPLOYEENUMBER.VALUE')Add_Entry To_List(#DROP_LIST)Endfor
List コレクションの例1のソース・コード
最初のフォームのソース
Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(319) Clientwidth(247) Dragstyle(Automatic) Height(346) Left(255) Top(111) Width(255) * 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(217)Define_Com Class(#PRIM_LVCL) Name(#LVCL_1) Displayposition(1) Parent(#DRAG_LIST) Source(#EMPNO) Width(53)Define_Com Class(#PRIM_LVCL) Name(#LVCL_2) Displayposition(2) Parent(#DRAG_LIST) Source(#SALARY) Width(45) Widthtype(Remainder)* Define the drop form (change this name 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<#Prim_ALPH>) Name(#PayLoadList) Reference(*Dynamic)Define_Com Class(#Prim_ALPH) Name(#EmployeeNumber) Reference(*Dynamic)* Dynamically create the list collection that is to to be the "payload"* for this drag operationSet_Ref Com(#PayLoadList) To(*Create_as #Prim_LCOL<#Prim_ALPH>)* Now fill the list collection with the employee numbers of all* the currently selected employeesSelectlist Named(#DRAG_LIST)Continue If('#Drag_List.Currentitem.Selected *ne True')Set_Ref Com(#EmployeeNumber) To(*Create_as #Prim_ALPH)Set Com(#EmployeeNumber) Value(#EmpNo)Invoke Method(#PayLoadList.Insert) Item(#EmployeeNumber)Endselect* FinishedSet Com(#Continue) Value(True)Set_Ref Com(#PayLoad) To(#PayLoadList)Set Com(#DragList) Dragliststyle(Selection)EndroutineEnd_Com
2番目のフォームのソース
Function Options(*DIRECT)Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(310) Clientwidth(137) Dragstyle(Automatic) Formstyle(StayOnTopChild) Height(337) Left(577) Top(120) Width(145)* The Drop List DefinitionDefine_Com Class(#PRIM_LTVW) Name(#DROP_LIST) Displayposition(1) Fullrowselect(True) Height(285) Left(16) Parent(#COM_OWNER) Tabposition(1) Top(8) Width(105)Define_Com Class(#PRIM_LVCL) Name(#LVCL_1) Displayposition(1) Parent(#DROP_LIST) Source(#EMPNO) Width(53) 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 alphas* accept it otherwise reject it .....If_Ref Com(#PayLoad) Is(*Instance_of #Prim_LCol<#Prim_alph>)Set Com(#AcceptDrop) Value(True)ElseSet Com(#AcceptDrop) Value(False)EndifEndroutine* =========================================* Handle the actual drop into the drop list* =========================================Evtroutine Handling(#Drop_List.DragDrop) Payload(#PayLoad)Define_Com Class(#Prim_LCOL<#Prim_ALPH>) Name(#PayLoadList) Reference(*Dynamic)* Cast the payload as a list colelction of alphas ....Set_Ref Com(#PayLoadList) To(*Dynamic #PayLoad)* Clear the drop list and fill it will all the employee numbers in the payload ...Clr_List Named(#DROP_LIST)For Each(#EmployeeNumber) In(#PayLoadList)Change Field(#EMPNO) To('#EMPLOYEENUMBER.VALUE')Add_Entry To_List(#DROP_LIST)EndforEndroutineEnd_Com
