Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

[ Image Removed |../../index.htm#lansa/l4wdev06_1070.htm]
現在地:

...

この例では、List コレクションを使用して、アイテムをフォームからフォームにドラッグ・アンド・ドロップする方法を説明します。

List コレクションは、順序付けされたコンポーネントのコレクションを提供します。List コレクションのコンポーネントは、指定された索引またはリストの先頭または末尾の参照で位置付けされます。インデックスには、常に1を基準とした値が付けられます。

この例では、ドラッグ・アンド・ドロップ操作の最初で選択された社員の社員番号と賃金情報がList コレクションに保存され、操作の最後にコレクションから他のフォームにこの情報が取得されます。

Image RemovedImage Added

コレクションの定義

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)
Endselect

...


Set_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)
Else
Set Com(#AcceptDrop) Value(False)
Endif
Endroutine

...

他の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)

...

property
Define_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 details
Select 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 operation
Set_

...

Ref Com(#PayLoadList)

...

To(*Create_

...

as #Prim_LCOL<#Prim_ALPH>)

...


* Now fill the list collection with the employee numbers of all

...


* the currently selected employees
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)
Endselect

...


*

...

Finished
Set 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(310)

...

Clientwidth(137)

...

Dragstyle(Automatic)

...

Formstyle(StayOnTopChild)

...

Height(337)

...

Left(577)

...

Top(120)

...

Width(145)

...


* The Drop List Definition
Define_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)
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<#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)
Endfor

...


Endroutine

...


End_Com

...