数据窗口拖放事件并不总是 return 对拖放位置控件的引用

Datawindow dragdrop event doesn't always return a reference to the control at the drop location

简而言之,我需要根据控件在拖动后放置在其上的对象类型来确定一些 window 行为。只要目标处的目标控件是列,这一切都很好,但如果它是任何其他对象,则不是。

假设我有一个包含两列和一个矩形的数据window。我们分别称它们为 c_1、c_2 和 r_1。

我将 c_1 拖放到 c_2 上:

dwo.name = c_2
dwo.type = column

很好,正是我所期望的行为。

我将 c_1 拖放到 r_1 上:

dwo.name = datawindow
dwo.type = datawindow

对数据window 本身的引用是returned。这太宽泛了,不能用作构建任何有意义的东西的基础,至少对我来说是这样。

在测试中,我似乎无法使 dragdrop return 成为对拖放位置控件的引用,除非它是一列。这是故意的,还是我的环境出了问题?如果我需要使 window 行为基于 dwo.type 或 dwo.name 的值,我该如何解决这个问题?

一种方法是根据数据窗口中的控件数组检查指针的 X 和 Y 坐标。

在数据窗口的一个事件中,您可以获得这样的对象列表:

is_selected_controls = is_null //both of these are string arrays
ls_objects = this.Describe( 'DataWindow.Objects')
ls_objects = ls_objects + '~t'
ll_pos = pos(ls_objects, '~t')
ll_orig_pos = 1

然后遍历数组并获取每个控件X、W、Width、Height

DO WHILE ll_pos > 0
    ls_object = mid(ls_objects, ll_orig_pos, ll_pos -ll_orig_pos)
    IF describe(ls_object + '.type') = 'line' THEN
        ls_x = this.Describe(ls_object + '.X1')
        ls_y = this.Describe(ls_object + '.Y1')
        ls_h = this.Describe(ls_object + '.Y2')
        ls_w = this.Describe(ls_object + '.X2')

    ELSE
        ls_x = this.Describe(ls_object + '.X')
        ls_y = this.Describe(ls_object + '.Y')
        ls_h = this.Describe(ls_object + '.height')
        ls_w = this.Describe(ls_object + '.width')
    END IF
    // compare the X,Y of the pointer to control position to see if it's
    // on the control, if it is exit the loop and do whatever...

    ll_orig_pos = ll_pos + 1
    ll_pos = pos(ls_objects, '~t', ll_orig_pos)
LOOP

使用函数GetObjectAtPointer

它可以让您确切地知道用户将东西放到了哪个对象上。

它 returns 一个形式为 objectname~trow 的字符串,您必须对其进行解析以确定您需要什么。